Whamcloud - gitweb
LU-5014 osd-ldiskfs: vfs_unlink api changed
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index f86da33..d01748d 100644 (file)
@@ -62,19 +62,12 @@ static void osd_push_ctxt(const struct osd_device *dev,
                           struct lvfs_run_ctxt *newctxt,
                           struct lvfs_run_ctxt *save)
 {
-        OBD_SET_CTXT_MAGIC(newctxt);
-        newctxt->pwdmnt = dev->od_mnt;
-        newctxt->pwd = dev->od_mnt->mnt_root;
-        newctxt->fs = get_ds();
+       OBD_SET_CTXT_MAGIC(newctxt);
+       newctxt->pwdmnt = dev->od_mnt;
+       newctxt->pwd = dev->od_mnt->mnt_root;
+       newctxt->fs = get_ds();
 
-        push_ctxt(save, newctxt, NULL);
-}
-
-static void osd_pop_ctxt(const struct osd_device *dev,
-                        struct lvfs_run_ctxt *new,
-                        struct lvfs_run_ctxt *save)
-{
-       pop_ctxt(save, new, NULL);
+       push_ctxt(save, newctxt);
 }
 
 /* utility to make a directory */
@@ -131,7 +124,7 @@ int osd_last_rcvd_subdir_count(struct osd_device *osd)
         struct dentry        *dlast;
         loff_t                off;
         int                   rc = 0;
-       int                   count = FILTER_SUBDIR_COUNT;
+       int                   count = OBJ_SUBDIR_COUNT;
 
         ENTRY;
 
@@ -182,8 +175,6 @@ static int osd_mdt_init(const struct lu_env *env, struct osd_device *dev)
 
        omm = dev->od_mdt_map;
 
-       LASSERT(dev->od_fsops);
-
        parent = osd_sb(dev)->s_root;
        osd_push_ctxt(dev, &new, &save);
 
@@ -192,7 +183,6 @@ static int osd_mdt_init(const struct lu_env *env, struct osd_device *dev)
        if (IS_ERR(d))
                GOTO(cleanup, rc = PTR_ERR(d));
 
-       ldiskfs_set_inode_state(d->d_inode, LDISKFS_STATE_LUSTRE_NO_OI);
        omm->omm_remote_parent = d;
 
        /* Set LMA for remote parent inode */
@@ -202,7 +192,7 @@ static int osd_mdt_init(const struct lu_env *env, struct osd_device *dev)
        GOTO(cleanup, rc);
 
 cleanup:
-       pop_ctxt(&save, &new, NULL);
+       pop_ctxt(&save, &new);
        if (rc) {
                if (omm->omm_remote_parent != NULL)
                        dput(omm->omm_remote_parent);
@@ -259,10 +249,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
                                   NULL);
        CDEBUG(D_INODE, "%s: add %s:%lu to remote parent %lu.\n", osd_name(osd),
               name, obj->oo_inode->i_ino, parent->d_inode->i_ino);
-       LASSERTF(parent->d_inode->i_nlink > 1, "%s: %lu nlink %d",
-                osd_name(osd), parent->d_inode->i_ino,
-                parent->d_inode->i_nlink);
-       parent->d_inode->i_nlink++;
+       ldiskfs_inc_count(oh->ot_handle, parent->d_inode);
        mark_inode_dirty(parent->d_inode);
        mutex_unlock(&parent->d_inode->i_mutex);
        RETURN(rc);
@@ -296,7 +283,8 @@ int osd_delete_from_remote_parent(const struct lu_env *env,
        dentry = osd_child_dentry_by_inode(env, parent->d_inode,
                                           name, strlen(name));
        mutex_lock(&parent->d_inode->i_mutex);
-       bh = osd_ldiskfs_find_entry(parent->d_inode, dentry, &de, NULL);
+       bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
+                                   NULL, NULL);
        if (bh == NULL) {
                mutex_unlock(&parent->d_inode->i_mutex);
                RETURN(-ENOENT);
@@ -304,10 +292,7 @@ int osd_delete_from_remote_parent(const struct lu_env *env,
        CDEBUG(D_INODE, "%s: el %s:%lu to remote parent %lu.\n", osd_name(osd),
               name, obj->oo_inode->i_ino, parent->d_inode->i_ino);
        rc = ldiskfs_delete_entry(oh->ot_handle, parent->d_inode, de, bh);
-       LASSERTF(parent->d_inode->i_nlink > 1, "%s: %lu nlink %d",
-                osd_name(osd), parent->d_inode->i_ino,
-                parent->d_inode->i_nlink);
-       parent->d_inode->i_nlink--;
+       ldiskfs_dec_count(oh->ot_handle, parent->d_inode);
        mark_inode_dirty(parent->d_inode);
        mutex_unlock(&parent->d_inode->i_mutex);
        brelse(bh);
@@ -339,7 +324,8 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
        dentry = osd_child_dentry_by_inode(oti->oti_env, parent->d_inode,
                                           name, strlen(name));
        mutex_lock(&parent->d_inode->i_mutex);
-       bh = osd_ldiskfs_find_entry(parent->d_inode, dentry, &de, NULL);
+       bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
+                                   NULL, NULL);
        if (bh == NULL) {
                rc = -ENOENT;
        } else {
@@ -391,9 +377,8 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
 
        CFS_INIT_LIST_HEAD(&dev->od_ost_map->om_seq_list);
        rwlock_init(&dev->od_ost_map->om_seq_list_lock);
-       sema_init(&dev->od_ost_map->om_dir_init_sem, 1);
+       mutex_init(&dev->od_ost_map->om_dir_init_mutex);
 
-        LASSERT(dev->od_fsops);
         osd_push_ctxt(dev, &new, &save);
 
        d = ll_lookup_one_len("O", rootd, strlen("O"));
@@ -413,7 +398,6 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
        }
 
        inode = d->d_inode;
-       ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
        dev->od_ost_map->om_root = d;
 
        /* 'What the @fid is' is not imporatant, because the object
@@ -425,7 +409,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
        GOTO(cleanup, rc);
 
 cleanup:
-       osd_pop_ctxt(dev, &new, &save);
+       pop_ctxt(&save, &new);
         if (IS_ERR(d)) {
                 OBD_FREE_PTR(dev->od_ost_map);
                 RETURN(PTR_ERR(d));
@@ -534,10 +518,9 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
                                struct dentry *dir, const char *name,
                                const struct lu_fid *fid,
                                const struct osd_inode_id *id,
-                               struct thandle *th)
+                               handle_t *th)
 {
        struct inode               *parent = dir->d_inode;
-       struct osd_thandle         *oh;
        struct dentry              *child;
        struct ldiskfs_dir_entry_2 *de;
        struct buffer_head         *bh;
@@ -549,9 +532,8 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
        int                         rc;
        ENTRY;
 
-       oh = container_of(th, struct osd_thandle, ot_super);
-       LASSERT(oh->ot_handle != NULL);
-       LASSERT(oh->ot_handle->h_transaction != NULL);
+       LASSERT(th != NULL);
+       LASSERT(th->h_transaction != NULL);
 
        child = &info->oti_child_dentry;
        child->d_parent = dir;
@@ -561,7 +543,7 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
 
        ll_vfs_dq_init(parent);
        mutex_lock(&parent->i_mutex);
-       bh = osd_ldiskfs_find_entry(parent, child, &de, NULL);
+       bh = osd_ldiskfs_find_entry(parent, &child->d_name, &de, NULL, NULL);
        if (bh == NULL)
                GOTO(out, rc = -ENOENT);
 
@@ -612,12 +594,12 @@ update:
         * is still valid. Since it was referenced by an invalid entry,
         * making it as invisible temporary may be not worse. OI scrub
         * will process it later. */
-       rc = ldiskfs_journal_get_write_access(oh->ot_handle, bh);
+       rc = ldiskfs_journal_get_write_access(th, bh);
        if (rc != 0)
                GOTO(out, rc);
 
        de->inode = cpu_to_le32(id->oii_ino);
-       rc = ldiskfs_journal_dirty_metadata(oh->ot_handle, bh);
+       rc = ldiskfs_journal_dirty_metadata(th, bh);
 
        GOTO(out, rc);
 
@@ -630,19 +612,17 @@ out:
 static int osd_obj_del_entry(struct osd_thread_info *info,
                             struct osd_device *osd,
                             struct dentry *dird, char *name,
-                            struct thandle *th)
+                            handle_t *th)
 {
        struct ldiskfs_dir_entry_2 *de;
        struct buffer_head         *bh;
-       struct osd_thandle         *oh;
        struct dentry              *child;
        struct inode               *dir = dird->d_inode;
        int                         rc;
        ENTRY;
 
-       oh = container_of(th, struct osd_thandle, ot_super);
-       LASSERT(oh->ot_handle != NULL);
-       LASSERT(oh->ot_handle->h_transaction != NULL);
+       LASSERT(th != NULL);
+       LASSERT(th->h_transaction != NULL);
 
 
        child = &info->oti_child_dentry;
@@ -655,9 +635,9 @@ static int osd_obj_del_entry(struct osd_thread_info *info,
        ll_vfs_dq_init(dir);
        mutex_lock(&dir->i_mutex);
        rc = -ENOENT;
-       bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
+       bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
        if (bh) {
-               rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
+               rc = ldiskfs_delete_entry(th, dir, de, bh);
                brelse(bh);
        }
        mutex_unlock(&dir->i_mutex);
@@ -669,9 +649,8 @@ int osd_obj_add_entry(struct osd_thread_info *info,
                      struct osd_device *osd,
                      struct dentry *dir, char *name,
                      const struct osd_inode_id *id,
-                     struct thandle *th)
+                     handle_t *th)
 {
-       struct osd_thandle *oh;
        struct dentry *child;
        struct inode *inode;
        int rc;
@@ -681,9 +660,8 @@ int osd_obj_add_entry(struct osd_thread_info *info,
        if (OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_NO_ENTRY))
                RETURN(0);
 
-       oh = container_of(th, struct osd_thandle, ot_super);
-       LASSERT(oh->ot_handle != NULL);
-       LASSERT(oh->ot_handle->h_transaction != NULL);
+       LASSERT(th != NULL);
+       LASSERT(th->h_transaction != NULL);
 
        inode = &info->oti_inode;
        inode->i_sb = osd_sb(osd);
@@ -702,7 +680,7 @@ int osd_obj_add_entry(struct osd_thread_info *info,
 
        ll_vfs_dq_init(dir->d_inode);
        mutex_lock(&dir->d_inode->i_mutex);
-       rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL);
+       rc = osd_ldiskfs_add_entry(th, child, inode, NULL);
        mutex_unlock(&dir->d_inode->i_mutex);
 
        RETURN(rc);
@@ -761,7 +739,6 @@ static int osd_seq_load_locked(struct osd_thread_info *info,
                GOTO(out_put, rc = -EFAULT);
 
        inode = seq_dir->d_inode;
-       ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
        osd_seq->oos_root = seq_dir;
 
        /* 'What the @fid is' is not imporatant, because the object
@@ -792,7 +769,6 @@ static int osd_seq_load_locked(struct osd_thread_info *info,
                }
 
                inode = dir->d_inode;
-               ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
                osd_seq->oos_dirs[i] = dir;
 
                /* 'What the @fid is' is not imporatant, because the object
@@ -837,7 +813,7 @@ static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
                RETURN(osd_seq);
 
        /* Serializing init process */
-       down(&map->om_dir_init_sem);
+       mutex_lock(&map->om_dir_init_mutex);
 
        /* Check whether the seq has been added */
        read_lock(&map->om_seq_list_lock);
@@ -866,7 +842,7 @@ static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
        write_unlock(&map->om_seq_list_lock);
 
 cleanup:
-       up(&map->om_dir_init_sem);
+       mutex_unlock(&map->om_dir_init_mutex);
        if (rc != 0) {
                if (osd_seq != NULL)
                        OBD_FREE_PTR(osd_seq);
@@ -918,7 +894,7 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
 
        dir = d_seq->d_inode;
        mutex_lock(&dir->i_mutex);
-       bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
+       bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
        mutex_unlock(&dir->i_mutex);
 
        if (bh == NULL)
@@ -939,7 +915,7 @@ int osd_obj_map_insert(struct osd_thread_info *info,
                       struct osd_device *osd,
                       const struct lu_fid *fid,
                       const struct osd_inode_id *id,
-                      struct thandle *th)
+                      handle_t *th)
 {
        struct osd_obj_map      *map;
        struct osd_obj_seq      *osd_seq;
@@ -982,7 +958,7 @@ again:
 }
 
 int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
-                      const struct lu_fid *fid, struct thandle *th)
+                      const struct lu_fid *fid, handle_t *th)
 {
        struct osd_obj_map      *map;
        struct osd_obj_seq      *osd_seq;
@@ -1016,7 +992,7 @@ int osd_obj_map_update(struct osd_thread_info *info,
                       struct osd_device *osd,
                       const struct lu_fid *fid,
                       const struct osd_inode_id *id,
-                      struct thandle *th)
+                      handle_t *th)
 {
        struct osd_obj_seq      *osd_seq;
        struct dentry           *d;
@@ -1088,7 +1064,7 @@ int osd_obj_map_recover(struct osd_thread_info *info,
        tgt_child->d_inode = inode;
 
        /* The non-initialized src_child may be destroyed. */
-       jh = ldiskfs_journal_start_sb(osd_sb(osd),
+       jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
                                osd_dto_credits_noquota[DTO_INDEX_DELETE] +
                                osd_dto_credits_noquota[DTO_INDEX_INSERT] +
                                osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
@@ -1100,7 +1076,7 @@ int osd_obj_map_recover(struct osd_thread_info *info,
 
        mutex_lock(&src_parent->i_mutex);
        mutex_lock(&dir->i_mutex);
-       bh = osd_ldiskfs_find_entry(dir, tgt_child, &de, NULL);
+       bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL);
        if (bh != NULL) {
                /* XXX: If some other object occupied the same slot. And If such
                 *      inode is zero-sized and with SUID+SGID, then means it is
@@ -1120,15 +1096,23 @@ int osd_obj_map_recover(struct osd_thread_info *info,
                 *
                 *      So keep it there before we have suitable solution. */
                brelse(bh);
+               mutex_unlock(&dir->i_mutex);
+               mutex_unlock(&src_parent->i_mutex);
+               ldiskfs_journal_stop(jh);
 
+               rc = -EEXIST;
                /* If the src object has never been modified, then remove it. */
                if (inode->i_size == 0 && inode->i_mode & S_ISUID &&
-                   inode->i_mode & S_ISGID)
-                       vfs_unlink(src_parent, src_child);
-               GOTO(unlock_src, rc = 0);
+                   inode->i_mode & S_ISGID) {
+                       rc = ll_vfs_unlink(src_parent, src_child);
+                       if (unlikely(rc == -ENOENT))
+                               rc = 0;
+               }
+               RETURN(rc);
        }
 
-       bh = osd_ldiskfs_find_entry(src_parent, src_child, &de, NULL);
+       bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, &de,
+                                   NULL, NULL);
        if (unlikely(bh == NULL))
                GOTO(unlock, rc = -ENOENT);
 
@@ -1143,8 +1127,6 @@ int osd_obj_map_recover(struct osd_thread_info *info,
 
 unlock:
        mutex_unlock(&dir->i_mutex);
-
-unlock_src:
        mutex_unlock(&src_parent->i_mutex);
        ldiskfs_journal_stop(jh);
        return rc;
@@ -1179,10 +1161,10 @@ osd_object_spec_find(struct osd_thread_info *info, struct osd_device *osd,
 
 int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
-                       struct thandle *th)
+                       handle_t *th)
 {
        struct dentry   *root;
-       char            *name;
+       char            *name = NULL;
        int              rc;
        ENTRY;
 
@@ -1200,10 +1182,10 @@ int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
 
 int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
-                       struct thandle *th)
+                       handle_t *th)
 {
        struct dentry   *root;
-       char            *name;
+       char            *name = NULL;
        int              rc;
        ENTRY;
 
@@ -1225,7 +1207,7 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
        struct dentry   *root;
        struct dentry   *dentry;
        struct inode    *inode;
-       char            *name;
+       char            *name = NULL;
        int             rc = -ENOENT;
        ENTRY;