Whamcloud - gitweb
LU-6207 osd: add osd_ost_fini in osd_obj_map_init
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index 8b91b64..bf317d0 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -66,6 +66,8 @@ static void osd_push_ctxt(const struct osd_device *dev,
        newctxt->pwdmnt = dev->od_mnt;
        newctxt->pwd = dev->od_mnt->mnt_root;
        newctxt->fs = get_ds();
+       newctxt->umask = current_umask();
+       newctxt->dt = NULL;
 
        push_ctxt(save, newctxt);
 }
@@ -118,7 +120,7 @@ out_up:
        return dchild;
 }
 
-int osd_last_rcvd_subdir_count(struct osd_device *osd)
+static int osd_last_rcvd_subdir_count(struct osd_device *osd)
 {
         struct lr_server_data lsd;
         struct dentry        *dlast;
@@ -367,15 +369,13 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
 
        /* to get subdir count from last_rcvd */
        rc = osd_last_rcvd_subdir_count(dev);
-       if (rc < 0) {
-               OBD_FREE_PTR(dev->od_ost_map);
-               RETURN(rc);
-       }
+       if (rc < 0)
+               GOTO(cleanup_alloc, rc);
 
        dev->od_ost_map->om_subdir_count = rc;
         rc = 0;
 
-       CFS_INIT_LIST_HEAD(&dev->od_ost_map->om_seq_list);
+       INIT_LIST_HEAD(&dev->od_ost_map->om_seq_list);
        rwlock_init(&dev->od_ost_map->om_seq_list_lock);
        mutex_init(&dev->od_ost_map->om_dir_init_mutex);
 
@@ -383,7 +383,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
 
        d = ll_lookup_one_len("O", rootd, strlen("O"));
        if (IS_ERR(d))
-               GOTO(cleanup, rc = PTR_ERR(d));
+               GOTO(cleanup_ctxt, rc = PTR_ERR(d));
        if (d->d_inode == NULL) {
                dput(d);
                /* The lookup() may be called again inside simple_mkdir().
@@ -391,7 +391,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
                 * mount time, it will not affect the whole performance. */
                d = simple_mkdir(rootd, dev->od_mnt, "O", 0755, 1);
                if (IS_ERR(d))
-                       GOTO(cleanup, rc = PTR_ERR(d));
+                       GOTO(cleanup_ctxt, rc = PTR_ERR(d));
 
                /* It is quite probably that the device is new formatted. */
                dev->od_maybe_new = 1;
@@ -404,16 +404,19 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
         * has no OI mapping, and only is visible inside the OSD.*/
        lu_igif_build(fid, inode->i_ino, inode->i_generation);
        rc = osd_ea_fid_set(info, inode, fid,
-                           LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
+                   LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
+       if (rc)
+               GOTO(cleanup_dentry, rc);
 
-       GOTO(cleanup, rc);
+       pop_ctxt(&save, &new);
+       RETURN(0);
 
-cleanup:
+cleanup_dentry:
+       dput(d);
+cleanup_ctxt:
        pop_ctxt(&save, &new);
-        if (IS_ERR(d)) {
-                OBD_FREE_PTR(dev->od_ost_map);
-                RETURN(PTR_ERR(d));
-        }
+cleanup_alloc:
+       OBD_FREE_PTR(dev->od_ost_map);
        return rc;
 }
 
@@ -422,7 +425,7 @@ static void osd_seq_free(struct osd_obj_map *map,
 {
        int j;
 
-       cfs_list_del_init(&osd_seq->oos_seq_list);
+       list_del_init(&osd_seq->oos_seq_list);
 
        if (osd_seq->oos_dirs) {
                for (j = 0; j < osd_seq->oos_subdir_count; j++) {
@@ -450,9 +453,8 @@ static void osd_ost_fini(struct osd_device *osd)
                return;
 
        write_lock(&map->om_seq_list_lock);
-       cfs_list_for_each_entry_safe(osd_seq, tmp,
-                                    &map->om_seq_list,
-                                    oos_seq_list) {
+       list_for_each_entry_safe(osd_seq, tmp, &map->om_seq_list,
+                                oos_seq_list) {
                osd_seq_free(map, osd_seq);
        }
        write_unlock(&map->om_seq_list_lock);
@@ -475,22 +477,24 @@ int osd_obj_map_init(const struct lu_env *env, struct osd_device *dev)
 
        /* prepare structures for MDS */
        rc = osd_mdt_init(env, dev);
+       if (rc)
+               osd_ost_fini(dev);
 
         RETURN(rc);
 }
 
-struct osd_obj_seq *osd_seq_find_locked(struct osd_obj_map *map, obd_seq seq)
+static struct osd_obj_seq *osd_seq_find_locked(struct osd_obj_map *map, u64 seq)
 {
        struct osd_obj_seq *osd_seq;
 
-       cfs_list_for_each_entry(osd_seq, &map->om_seq_list, oos_seq_list) {
+       list_for_each_entry(osd_seq, &map->om_seq_list, oos_seq_list) {
                if (osd_seq->oos_seq == seq)
                        return osd_seq;
        }
        return NULL;
 }
 
-struct osd_obj_seq *osd_seq_find(struct osd_obj_map *map, obd_seq seq)
+static struct osd_obj_seq *osd_seq_find(struct osd_obj_map *map, u64 seq)
 {
        struct osd_obj_seq *osd_seq;
 
@@ -599,7 +603,7 @@ update:
                GOTO(out, rc);
 
        de->inode = cpu_to_le32(id->oii_ino);
-       rc = ldiskfs_journal_dirty_metadata(th, bh);
+       rc = ldiskfs_handle_dirty_metadata(th, NULL, bh);
 
        GOTO(out, rc);
 
@@ -645,11 +649,11 @@ static int osd_obj_del_entry(struct osd_thread_info *info,
        RETURN(rc);
 }
 
-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,
-                     handle_t *th)
+static 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,
+                            handle_t *th)
 {
        struct dentry *child;
        struct inode *inode;
@@ -663,7 +667,14 @@ int osd_obj_add_entry(struct osd_thread_info *info,
        LASSERT(th != NULL);
        LASSERT(th->h_transaction != NULL);
 
-       inode = &info->oti_inode;
+       inode = info->oti_inode;
+       if (unlikely(inode == NULL)) {
+               OBD_ALLOC_PTR(inode);
+               if (inode == NULL)
+                       RETURN(-ENOMEM);
+               info->oti_inode = inode;
+       }
+
        inode->i_sb = osd_sb(osd);
        osd_id_to_inode(inode, id);
        inode->i_mode = S_IFREG; /* for type in ldiskfs dir entry */
@@ -693,7 +704,7 @@ int osd_obj_add_entry(struct osd_thread_info *info,
  * debug messages to objects in the future, and the legacy space
  * of FID_SEQ_OST_MDT0 will be unused in the future.
  **/
-static inline void osd_seq_name(char *seq_name, size_t name_size, obd_seq seq)
+static inline void osd_seq_name(char *seq_name, size_t name_size, u64 seq)
 {
        snprintf(seq_name, name_size,
                 (fid_seq_is_rsvd(seq) ||
@@ -702,7 +713,7 @@ static inline void osd_seq_name(char *seq_name, size_t name_size, obd_seq seq)
 }
 
 static inline void osd_oid_name(char *name, size_t name_size,
-                               const struct lu_fid *fid, obd_id id)
+                               const struct lu_fid *fid, u64 id)
 {
        snprintf(name, name_size,
                 (fid_seq_is_rsvd(fid_seq(fid)) ||
@@ -797,7 +808,7 @@ out_err:
 }
 
 static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
-                                       struct osd_device *osd, obd_seq seq)
+                                       struct osd_device *osd, u64 seq)
 {
        struct osd_obj_map      *map;
        struct osd_obj_seq      *osd_seq;
@@ -828,7 +839,7 @@ static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
        if (osd_seq == NULL)
                GOTO(cleanup, rc = -ENOMEM);
 
-       CFS_INIT_LIST_HEAD(&osd_seq->oos_seq_list);
+       INIT_LIST_HEAD(&osd_seq->oos_seq_list);
        osd_seq->oos_seq = seq;
        /* Init subdir count to be 32, but each seq can have
         * different subdir count */
@@ -838,7 +849,7 @@ static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
                GOTO(cleanup, rc);
 
        write_lock(&map->om_seq_list_lock);
-       cfs_list_add(&osd_seq->oos_seq_list, &map->om_seq_list);
+       list_add(&osd_seq->oos_seq_list, &map->om_seq_list);
        write_unlock(&map->om_seq_list_lock);
 
 cleanup:
@@ -904,8 +915,11 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
        brelse(bh);
 
        inode = osd_iget(info, dev, id);
-       if (IS_ERR(inode))
-               RETURN(PTR_ERR(inode));
+       if (IS_ERR(inode)) {
+               int rc = PTR_ERR(inode);
+
+               RETURN(rc == -ENOENT ? -ESTALE : rc);
+       }
 
        iput(inode);
        RETURN(0);
@@ -921,7 +935,7 @@ int osd_obj_map_insert(struct osd_thread_info *info,
        struct osd_obj_seq      *osd_seq;
        struct dentry           *d;
        struct ost_id           *ostid = &info->oti_ostid;
-       obd_id                   oid;
+       u64                      oid;
        int                     dirn, rc = 0;
        char                    name[32];
        ENTRY;
@@ -1104,7 +1118,7 @@ int osd_obj_map_recover(struct osd_thread_info *info,
                /* 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) {
-                       rc = vfs_unlink(src_parent, src_child);
+                       rc = ll_vfs_unlink(src_parent, src_child);
                        if (unlikely(rc == -ENOENT))
                                rc = 0;
                }
@@ -1164,7 +1178,7 @@ int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
                        handle_t *th)
 {
        struct dentry   *root;
-       char            *name;
+       char            *name = NULL;
        int              rc;
        ENTRY;
 
@@ -1185,7 +1199,7 @@ int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
                        handle_t *th)
 {
        struct dentry   *root;
-       char            *name;
+       char            *name = NULL;
        int              rc;
        ENTRY;
 
@@ -1207,7 +1221,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;