Whamcloud - gitweb
b=3920
[fs/lustre-release.git] / lustre / mds / mds_unlink_open.c
index 87e9a27..c11328c 100644 (file)
@@ -60,6 +60,7 @@ int mds_open_unlink_rename(struct mds_update_record *rec,
         struct dentry *pending_child;
         char fidname[LL_FID_NAMELEN];
         int fidlen = 0, rc;
+        unsigned mode;
         ENTRY;
 
         LASSERT(!mds_inode_is_orphan(dchild->d_inode));
@@ -81,18 +82,26 @@ int mds_open_unlink_rename(struct mds_update_record *rec,
                 GOTO(out_dput, rc = 0);
         }
 
-        *handle = fsfilt_start(obd, pending_dir, FSFILT_OP_RENAME, NULL);
-        if (IS_ERR(*handle))
-                GOTO(out_dput, rc = PTR_ERR(*handle));
-
-        lock_kernel();
-        rc = vfs_rename(dparent->d_inode, dchild, pending_dir, pending_child);
-        unlock_kernel();
+        /* link() is semanticaly-wrong for S_IFDIR, so we set S_IFREG
+         * for linking and return real mode back then -bzzz */
+        mode = dchild->d_inode->i_mode;
+        dchild->d_inode->i_mode = S_IFREG;
+        rc = vfs_link(dchild, pending_dir, pending_child);
         if (rc)
-                CERROR("error renaming orphan %lu/%s to PENDING: rc = %d\n",
-                       dparent->d_inode->i_ino, rec->ur_name, rc);
+                CERROR("error linking orphan %s to PENDING: rc = %d\n",
+                       rec->ur_name, rc);
         else
                 mds_inode_set_orphan(dchild->d_inode);
+
+        /* return mode and correct i_nlink if inode is directory */
+        LASSERT(dchild->d_inode->i_nlink == 1);
+        dchild->d_inode->i_mode = mode;
+        if ((mode & S_IFMT) == S_IFDIR) {
+                dchild->d_inode->i_nlink++;
+                pending_dir->i_nlink++;
+        }
+        mark_inode_dirty(dchild->d_inode);
+
 out_dput:
         dput(pending_child);
 out_lock:
@@ -129,8 +138,9 @@ static int mds_osc_destroy_orphan(struct mds_obd *mds,
         if (oa == NULL)
                 GOTO(out_free_memmd, rc = -ENOMEM);
         oa->o_id = lsm->lsm_object_id;
+        oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
         oa->o_mode = inode->i_mode & S_IFMT;
-        oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
+        oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
 
         if (log_unlink && logcookies) {
                 oa->o_valid |= OBD_MD_FLCOOKIE;
@@ -140,7 +150,7 @@ static int mds_osc_destroy_orphan(struct mds_obd *mds,
         rc = obd_destroy(mds->mds_osc_exp, oa, lsm, &oti);
         obdo_free(oa);
         if (rc)
-                CERROR("destroy orphan objid 0x"LPX64" on ost error "
+                CDEBUG(D_INODE, "destroy orphan objid 0x"LPX64" on ost error "
                        "%d\n", lsm->lsm_object_id, rc);
 out_free_memmd:
         obd_free_memmd(mds->mds_osc_exp, &lsm);
@@ -219,7 +229,7 @@ static int mds_unlink_orphan(struct obd_device *obd, struct dentry *dchild,
                                            mds->mds_max_cookiesize) > 0)
                         log_unlink = 1;
         }
-        err = fsfilt_commit(obd, pending_dir, handle, 0);
+        err = fsfilt_commit(obd, mds->mds_sb, pending_dir, handle, 0);
         if (err) {
                 CERROR("error committing orphan unlink: %d\n", err);
                 if (!rc)
@@ -240,7 +250,7 @@ out_free_lmm:
 int mds_cleanup_orphans(struct obd_device *obd)
 {
         struct mds_obd *mds = &obd->u.mds;
-        struct obd_run_ctxt saved;
+        struct lvfs_run_ctxt saved;
         struct file *file;
         struct dentry *dchild, *dentry;
         struct vfsmount *mnt;
@@ -252,7 +262,7 @@ int mds_cleanup_orphans(struct obd_device *obd)
         int rc = 0, item = 0, namlen;
         ENTRY;
 
-        push_ctxt(&saved, &obd->obd_ctxt, NULL);
+        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         dentry = dget(mds->mds_pending_dir);
         if (IS_ERR(dentry))
                 GOTO(err_pop, rc = PTR_ERR(dentry));
@@ -311,7 +321,7 @@ int mds_cleanup_orphans(struct obd_device *obd)
                         item ++;
                         CWARN("removed orphan %s from MDS and OST\n", d_name);
                 } else {
-                        CERROR("removed orphan %s from MDS and OST failed,"
+                        CDEBUG(D_INODE, "removed orphan %s from MDS/OST failed,"
                                " rc = %d\n", d_name, rc);
                         rc = 0;
                 }
@@ -325,7 +335,7 @@ err_out:
                 OBD_FREE(dirent, sizeof(*dirent));
         }
 err_pop:
-        pop_ctxt(&saved, &obd->obd_ctxt, NULL);
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         if (rc == 0)
                 rc = item;
         RETURN(rc);