Whamcloud - gitweb
WARNING: This commit breaks everything. It will be back in shape within 12
[fs/lustre-release.git] / lustre / llite / namei.c
index ce2cdaa..70990cb 100644 (file)
@@ -92,37 +92,47 @@ static int ll_find_inode(struct inode *inode, unsigned long ino, void *opaque)
 
 static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
 {
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
         struct inode * inode = NULL;
         struct ll_sb_info *sbi = ll_i2sbi(dir);
-        int err;
-        int type;
+        struct ll_inode_md md;
+        int err, type;
         ino_t ino;
-        
+
         ENTRY;
         if (dentry->d_name.len > EXT2_NAME_LEN)
-                return ERR_PTR(-ENAMETOOLONG);
+                RETURN(ERR_PTR(-ENAMETOOLONG));
 
         ino = ll_inode_by_name(dir, dentry, &type);
         if (!ino)
-                goto negative;
+                GOTO(negative, NULL);
 
-        err = mdc_getattr(&sbi->ll_mds_client, ino, type,
-                          OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &request);
+        err = mdc_getattr(&sbi->ll_mds_client, sbi->ll_mds_conn, ino, type,
+                          OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
         if (err) {
-                CERROR("failure %d inode %ld\n", err, ino);
+                CERROR("failure %d inode %ld\n", err, (long)ino);
                 ptlrpc_free_req(request);
-                EXIT;
-                return ERR_PTR(-abs(err)); 
+                RETURN(ERR_PTR(-abs(err)));
         }
 
-        inode = iget4(dir->i_sb, ino, ll_find_inode,
-                      lustre_msg_buf(request->rq_repmsg, 0));
+        if (S_ISREG(type)) {
+                if (request->rq_repmsg->bufcount < 2 ||
+                    request->rq_repmsg->buflens[1] != sizeof(struct obdo))
+                        LBUG();
+
+                md.obdo = lustre_msg_buf(request->rq_repmsg, 1);
+        } else
+                md.obdo = NULL;
+
+        md.body = lustre_msg_buf(request->rq_repmsg, 0);
+
+        inode = iget4(dir->i_sb, ino, ll_find_inode, &md);
 
         ptlrpc_free_req(request);
         if (!inode) 
-                return ERR_PTR(-ENOMEM);
+                RETURN(ERR_PTR(-ENOMEM));
 
+        EXIT;
  negative:
         d_add(dentry, inode);
         return NULL;
@@ -130,34 +140,38 @@ static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
 
 static struct inode *ll_create_node(struct inode *dir, const char *name, 
                                     int namelen, const char *tgt, int tgtlen, 
-                                    int mode, __u64 id)
+                                    int mode, __u64 extra, struct obdo *obdo)
 {
         struct inode *inode;
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
         struct mds_body *body;
         int err;
         time_t time = CURRENT_TIME;
         struct ll_sb_info *sbi = ll_i2sbi(dir);
+        struct ll_inode_md md;
 
         ENTRY;
 
-        err = mdc_create(&sbi->ll_mds_client, dir, name, namelen, tgt, tgtlen,
-                         mode, id,  current->uid, current->gid, time, &request);
+        err = mdc_create(&sbi->ll_mds_client, sbi->ll_mds_conn, dir, name,
+                         namelen, tgt, tgtlen, mode, current->fsuid,
+                         current->fsgid, time, extra, obdo, &request);
         if (err) { 
                 inode = ERR_PTR(err);
                 GOTO(out, err);
         }
         body = lustre_msg_buf(request->rq_repmsg, 0);
-        body->valid = OBD_MD_FLNOTOBD;
+        body->valid = (__u32)OBD_MD_FLNOTOBD;
 
-        body->objid = id; 
         body->nlink = 1;
         body->atime = body->ctime = body->mtime = time;
+        body->uid = current->fsuid;
+        body->gid = current->fsgid;
         body->mode = mode;
-        CDEBUG(D_INODE, "-- new_inode: objid %lld, ino %d, mode %o\n",
-               body->objid, body->ino, body->mode); 
 
-        inode = iget4(dir->i_sb, body->ino, ll_find_inode, body);
+        md.body = body;
+        md.obdo = obdo;
+
+        inode = iget4(dir->i_sb, body->ino, ll_find_inode, &md);
         if (IS_ERR(inode)) {
                 CERROR("new_inode -fatal:  %ld\n", PTR_ERR(inode));
                 inode = ERR_PTR(-EIO);
@@ -179,18 +193,19 @@ static struct inode *ll_create_node(struct inode *dir, const char *name,
  out:
         ptlrpc_free_req(request);
         return inode;
-} /* ll_new_inode */
+}
 
 int ll_mdc_unlink(struct inode *dir, struct inode *child,
                   const char *name, int len)
 {
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
         int err;
         struct ll_sb_info *sbi = ll_i2sbi(dir);
 
         ENTRY;
 
-        err = mdc_unlink(&sbi->ll_mds_client, dir, child, name, len, &request);
+        err = mdc_unlink(&sbi->ll_mds_client, sbi->ll_mds_conn, dir, child,
+                         name, len, &request);
         ptlrpc_free_req(request);
 
         EXIT;
@@ -200,13 +215,14 @@ int ll_mdc_unlink(struct inode *dir, struct inode *child,
 int ll_mdc_link(struct dentry *src, struct inode *dir, 
                 const char *name, int len)
 {
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
         int err;
         struct ll_sb_info *sbi = ll_i2sbi(dir);
 
         ENTRY;
 
-        err = mdc_link(&sbi->ll_mds_client, src, dir, name, len, &request);
+        err = mdc_link(&sbi->ll_mds_client, sbi->ll_mds_conn, src, dir, name,
+                       len, &request);
         ptlrpc_free_req(request);
 
         EXIT;
@@ -216,13 +232,13 @@ int ll_mdc_link(struct dentry *src, struct inode *dir,
 int ll_mdc_rename(struct inode *src, struct inode *tgt, 
                   struct dentry *old, struct dentry *new)
 {
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
         int err;
         struct ll_sb_info *sbi = ll_i2sbi(src);
 
         ENTRY;
 
-        err = mdc_rename(&sbi->ll_mds_client, src, tgt, 
+        err = mdc_rename(&sbi->ll_mds_client, sbi->ll_mds_conn, src, tgt, 
                          old->d_name.name, old->d_name.len, 
                          new->d_name.name, new->d_name.len, &request);
         ptlrpc_free_req(request);
@@ -242,42 +258,55 @@ int ll_mdc_rename(struct inode *src, struct inode *tgt,
 
 static int ll_create (struct inode * dir, struct dentry * dentry, int mode)
 {
-        int err
+        int err, rc;
         struct obdo oa;
-        struct inode * inode;
+        struct inode *inode;
 
-        memset(&oa, 0, sizeof(oa)); 
-        oa.o_valid = OBD_MD_FLMODE; 
+        memset(&oa, 0, sizeof(oa));
+        oa.o_valid = OBD_MD_FLMODE;
         oa.o_mode = S_IFREG | 0600;
-        err = obd_create(ll_i2obdconn(dir), &oa);  
-        if (err) { 
-                EXIT; 
-                return err;
-        }
+        rc = obd_create(ll_i2obdconn(dir), &oa);
+        if (rc) {
+               CERROR("error creating OST object: rc = %d\n", rc);
+                RETURN(rc);
+       }
 
         mode = mode | S_IFREG;
-        CDEBUG(D_DENTRY, "name %s mode %o o_id %lld\n", 
-               dentry->d_name.name, mode, oa.o_id);
+        CDEBUG(D_DENTRY, "name %s mode %o o_id %lld\n",
+               dentry->d_name.name, mode, (unsigned long long)oa.o_id);
         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len, 
-                               NULL, 0, mode, oa.o_id);
-        err = PTR_ERR(inode);
-        if (!IS_ERR(inode)) {
-                // XXX clean up the object
-                inode->i_op = &ll_file_inode_operations;
-                inode->i_fop = &ll_file_operations;
-                inode->i_mapping->a_ops = &ll_aops;
-                err = ext2_add_nondir(dentry, inode);
-        }
-        EXIT;
-        return err;
+                               NULL, 0, mode, 0, &oa);
+
+       if (IS_ERR(inode)) {
+               rc = PTR_ERR(inode);
+               CERROR("error creating MDS object for id %Ld: rc = %d\n",
+                      (unsigned long long)oa.o_id, rc);
+               GOTO(out_destroy, rc);
+       }
+
+       inode->i_op = &ll_file_inode_operations;
+       inode->i_fop = &ll_file_operations;
+       inode->i_mapping->a_ops = &ll_aops;
+       rc = ext2_add_nondir(dentry, inode);
+       /* XXX Handle err, but this will probably get more complex anyways */
+
+        RETURN(rc);
+
+out_destroy:
+        err = obd_destroy(ll_i2obdconn(dir), &oa);
+       if (err)
+               CERROR("error destroying object %Ld in error path: err = %d\n",
+                      (unsigned long long)oa.o_id, err);
+       return err;
 } /* ll_create */
 
 
-static int ll_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
+static int ll_mknod (struct inode * dir, struct dentry *dentry, int mode,
+                     int rdev)
 {
         struct inode * inode = ll_create_node(dir, dentry->d_name.name, 
                                               dentry->d_name.len, NULL, 0,
-                                              mode, 0);
+                                              mode, rdev, NULL);
         int err = PTR_ERR(inode);
         if (!IS_ERR(inode)) {
                 init_special_inode(inode, mode, rdev);
@@ -299,7 +328,7 @@ static int ll_symlink (struct inode * dir, struct dentry * dentry,
 
         inode = ll_create_node(dir, dentry->d_name.name, 
                                dentry->d_name.len, symname, l,
-                               S_IFLNK | S_IRWXUGO, 0);
+                               S_IFLNK | S_IRWXUGO, 0, NULL);
         err = PTR_ERR(inode);
         if (IS_ERR(inode))
                 return err;
@@ -359,7 +388,7 @@ static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 
         inode = ll_create_node (dir, dentry->d_name.name, 
                                 dentry->d_name.len, NULL, 0, 
-                                S_IFDIR | mode, 0);
+                                S_IFDIR | mode, 0, NULL);
         err = PTR_ERR(inode);
         if (IS_ERR(inode))
                 goto out_dir;