9p: Implement client side of setattr for 9P2000.L protocol.
authorSripathi Kodi <sripathik@in.ibm.com>
Fri, 18 Jun 2010 06:20:10 +0000 (11:50 +0530)
committerEric Van Hensbergen <ericvh@gmail.com>
Mon, 2 Aug 2010 19:25:10 +0000 (14:25 -0500)
    SYNOPSIS

      size[4] Tsetattr tag[2] attr[n]

      size[4] Rsetattr tag[2]

    DESCRIPTION

      The setattr command changes some of the file status information.
      attr resembles the iattr structure used in Linux kernel. It
      specifies which status parameter is to be changed and to what
      value. It is laid out as follows:

         valid[4]
            specifies which status information is to be changed. Possible
            values are:
            ATTR_MODE       (1 << 0)
            ATTR_UID        (1 << 1)
            ATTR_GID        (1 << 2)
            ATTR_SIZE       (1 << 3)
            ATTR_ATIME      (1 << 4)
            ATTR_MTIME      (1 << 5)
            ATTR_ATIME_SET  (1 << 7)
            ATTR_MTIME_SET  (1 << 8)

            The last two bits represent whether the time information
            is being sent by the client's user space. In the absense
            of these bits the server always uses server's time.

         mode[4]
            File permission bits

         uid[4]
            Owner id of file

         gid[4]
            Group id of the file

         size[8]
            File size

         atime_sec[8]
            Time of last file access, seconds

         atime_nsec[8]
            Time of last file access, nanoseconds

         mtime_sec[8]
            Time of last file modification, seconds

         mtime_nsec[8]
            Time of last file modification, nanoseconds

Explanation of the patches:
--------------------------

*) The kernel just copies relevent contents of iattr structure to
   p9_iattr_dotl structure and passes it down to the client. The
   only check it has is calling inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file
   parameters because I don't think these are needed in our case.
   The client user space can request updating just ctime by calling
   chown(fd, -1, -1). This is handled on server side without a need
   for putting ctime on the wire.
*) The server currently supports changing mode, time, ownership and
   size of the file.
*) 9P RFC says "Either all the changes in wstat request happen, or
   none of them does: if the request succeeds, all changes were made;
   if it fails, none were."
   I have not done anything to implement this specifically because I
   don't see a reason.

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fs/9p/vfs_inode.c
include/net/9p/9p.h
include/net/9p/client.h
net/9p/client.c
net/9p/protocol.c

index afcb8d8893820b31441eafcab35dec76a1a9d6f7..a90324f4546a4830daaa078272e12e34af8e775c 100644 (file)
@@ -976,6 +976,49 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
        return retval;
 }
 
+/**
+ * v9fs_vfs_setattr_dotl - set file metadata
+ * @dentry: file whose metadata to set
+ * @iattr: metadata assignment structure
+ *
+ */
+
+static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
+{
+       int retval;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid;
+       struct p9_iattr_dotl p9attr;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "\n");
+
+       retval = inode_change_ok(dentry->d_inode, iattr);
+       if (retval)
+               return retval;
+
+       p9attr.valid = iattr->ia_valid;
+       p9attr.mode = iattr->ia_mode;
+       p9attr.uid = iattr->ia_uid;
+       p9attr.gid = iattr->ia_gid;
+       p9attr.size = iattr->ia_size;
+       p9attr.atime_sec = iattr->ia_atime.tv_sec;
+       p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
+       p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
+       p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
+
+       retval = -EPERM;
+       v9ses = v9fs_inode2v9ses(dentry->d_inode);
+       fid = v9fs_fid_lookup(dentry);
+       if (IS_ERR(fid))
+               return PTR_ERR(fid);
+
+       retval = p9_client_setattr(fid, &p9attr);
+       if (retval >= 0)
+               retval = inode_setattr(dentry->d_inode, iattr);
+
+       return retval;
+}
+
 /**
  * v9fs_stat2inode - populate an inode structure with mistat info
  * @stat: Plan 9 metadata (mistat) structure
@@ -1400,7 +1443,7 @@ static const struct inode_operations v9fs_dir_inode_operations_dotl = {
        .mknod = v9fs_vfs_mknod,
        .rename = v9fs_vfs_rename,
        .getattr = v9fs_vfs_getattr_dotl,
-       .setattr = v9fs_vfs_setattr,
+       .setattr = v9fs_vfs_setattr_dotl,
 };
 
 static const struct inode_operations v9fs_dir_inode_operations = {
@@ -1422,7 +1465,7 @@ static const struct inode_operations v9fs_file_inode_operations = {
 
 static const struct inode_operations v9fs_file_inode_operations_dotl = {
        .getattr = v9fs_vfs_getattr_dotl,
-       .setattr = v9fs_vfs_setattr,
+       .setattr = v9fs_vfs_setattr_dotl,
 };
 
 static const struct inode_operations v9fs_symlink_inode_operations = {
@@ -1438,5 +1481,5 @@ static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
        .follow_link = v9fs_vfs_follow_link,
        .put_link = v9fs_vfs_put_link,
        .getattr = v9fs_vfs_getattr_dotl,
-       .setattr = v9fs_vfs_setattr,
+       .setattr = v9fs_vfs_setattr_dotl,
 };
index ab12e1c9cc7ebb23830ed9687b518996a8b029f8..7f64d72f6c61d6ddc00c20ac73043d4124f8c43c 100644 (file)
@@ -135,6 +135,8 @@ enum p9_msg_t {
        P9_RRENAME,
        P9_TGETATTR = 24,
        P9_RGETATTR,
+       P9_TSETATTR = 26,
+       P9_RSETATTR,
        P9_TREADDIR = 40,
        P9_RREADDIR,
        P9_TVERSION = 100,
@@ -406,6 +408,32 @@ struct p9_stat_dotl {
 #define P9_STATS_BASIC         0x000007ffULL /* Mask for fields up to BLOCKS */
 #define P9_STATS_ALL           0x00003fffULL /* Mask for All fields above */
 
+/**
+ * struct p9_iattr_dotl - P9 inode attribute for setattr
+ * @valid: bitfield specifying which fields are valid
+ *         same as in struct iattr
+ * @mode: File permission bits
+ * @uid: user id of owner
+ * @gid: group id
+ * @size: File size
+ * @atime_sec: Last access time, seconds
+ * @atime_nsec: Last access time, nanoseconds
+ * @mtime_sec: Last modification time, seconds
+ * @mtime_nsec: Last modification time, nanoseconds
+ */
+
+struct p9_iattr_dotl {
+       u32 valid;
+       u32 mode;
+       u32 uid;
+       u32 gid;
+       u64 size;
+       u64 atime_sec;
+       u64 atime_nsec;
+       u64 mtime_sec;
+       u64 mtime_nsec;
+};
+
 /* Structures for Protocol Operations */
 struct p9_tstatfs {
        u32 fid;
index 6462eec435bcec6b76c82c5a714c4bc5dce533d0..afdc385152f601934c45f7f97e236cccae436781 100644 (file)
@@ -237,6 +237,7 @@ int p9dirent_read(char *buf, int len, struct p9_dirent *dirent,
                                                        int proto_version);
 struct p9_wstat *p9_client_stat(struct p9_fid *fid);
 int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
+int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *attr);
 
 struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid,
                                                        u64 request_mask);
index 5e97118da3bf85eeb45b063998d4fb6d2cccd79d..b2f70ec889c225808f483999fb3d17593858ad63 100644 (file)
@@ -1426,6 +1426,36 @@ error:
 }
 EXPORT_SYMBOL(p9_client_wstat);
 
+int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *p9attr)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+
+       err = 0;
+       clnt = fid->clnt;
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TSETATTR fid %d\n", fid->fid);
+       P9_DPRINTK(P9_DEBUG_9P,
+               "    valid=%x mode=%x uid=%d gid=%d size=%lld\n"
+               "    atime_sec=%lld atime_nsec=%lld\n"
+               "    mtime_sec=%lld mtime_nsec=%lld\n",
+               p9attr->valid, p9attr->mode, p9attr->uid, p9attr->gid,
+               p9attr->size, p9attr->atime_sec, p9attr->atime_nsec,
+               p9attr->mtime_sec, p9attr->mtime_nsec);
+
+       req = p9_client_rpc(clnt, P9_TSETATTR, "dI", fid->fid, p9attr);
+
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RSETATTR fid %d\n", fid->fid);
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_setattr);
+
 int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb)
 {
        int err;
index 3e4f776958917f94486dde65cd6b1b8e19c7709d..3acd3afb20c857f6f3d2451a6ce1d7ba5c14af76 100644 (file)
@@ -516,6 +516,23 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
                                }
                        }
                        break;
+               case 'I':{
+                               struct p9_iattr_dotl *p9attr = va_arg(ap,
+                                                       struct p9_iattr_dotl *);
+
+                               errcode = p9pdu_writef(pdu, proto_version,
+                                                       "ddddqqqqq",
+                                                       p9attr->valid,
+                                                       p9attr->mode,
+                                                       p9attr->uid,
+                                                       p9attr->gid,
+                                                       p9attr->size,
+                                                       p9attr->atime_sec,
+                                                       p9attr->atime_nsec,
+                                                       p9attr->mtime_sec,
+                                                       p9attr->mtime_nsec);
+                       }
+                       break;
                case '?':
                        if ((proto_version != p9_proto_2000u) &&
                                (proto_version != p9_proto_2000L))