Whamcloud - gitweb
LU-8147 osd-zfs: fix osd_mount error path
[fs/lustre-release.git] / lustre / osd-zfs / osd_oi.c
index b805643..0802bf4 100644 (file)
 /*
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
- */
-/*
- * Copyright (c) 2012, 2013, Intel Corporation.
- * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -69,8 +67,6 @@
 #include <sys/sa_impl.h>
 #include <sys/txg.h>
 
-static char *oi_tag = "osd_mount, oi";
-
 #define OSD_OI_FID_NR         (1UL << 7)
 #define OSD_OI_FID_NR_MAX     (1UL << OSD_OI_FID_OID_BITS_MAX)
 unsigned int osd_oi_count = OSD_OI_FID_NR;
@@ -98,6 +94,7 @@ static const struct named_oid oids[] = {
        { OFD_HEALTH_CHECK_OID,         HEALTH_CHECK },
        { ACCT_USER_OID,                "acct_usr_inode" },
        { ACCT_GROUP_OID,               "acct_grp_inode" },
+       { REPLY_DATA_OID,               REPLY_DATA },
        { 0,                            NULL }
 };
 
@@ -123,7 +120,7 @@ osd_oi_lookup(const struct lu_env *env, struct osd_device *o,
        struct zpl_direntry     *zde = &osd_oti_get(env)->oti_zde.lzd_reg;
        int                      rc;
 
-       rc = -zap_lookup(o->od_objset.os, parent, name, 8, 1, (void *)zde);
+       rc = -zap_lookup(o->od_os, parent, name, 8, 1, (void *)zde);
        if (rc)
                return rc;
 
@@ -131,10 +128,9 @@ osd_oi_lookup(const struct lu_env *env, struct osd_device *o,
        if (rc >= sizeof(oi->oi_name))
                return -E2BIG;
 
-       rc = 0;
        oi->oi_zapid = zde->zde_dnode;
 
-       return rc;
+       return 0;
 }
 
 /**
@@ -151,12 +147,12 @@ osd_oi_create(const struct lu_env *env, struct osd_device *o,
        int                      rc;
 
        /* verify it doesn't already exist */
-       rc = -zap_lookup(o->od_objset.os, parent, name, 8, 1, (void *)zde);
+       rc = -zap_lookup(o->od_os, parent, name, 8, 1, (void *)zde);
        if (rc == 0)
                return -EEXIST;
 
        /* create fid-to-dnode index */
-       tx = dmu_tx_create(o->od_objset.os);
+       tx = dmu_tx_create(o->od_os);
        if (tx == NULL)
                return -ENOMEM;
 
@@ -175,18 +171,18 @@ osd_oi_create(const struct lu_env *env, struct osd_device *o,
        la->la_valid = LA_MODE | LA_UID | LA_GID;
        la->la_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
        la->la_uid = la->la_gid = 0;
-       __osd_zap_create(env, &o->od_objset, &db, tx, la, parent, oi_tag, 0);
+       __osd_zap_create(env, o, &db, tx, la, parent, 0);
 
        zde->zde_dnode = db->db_object;
        zde->zde_pad = 0;
        zde->zde_type = IFTODT(S_IFDIR);
 
-       rc = -zap_add(o->od_objset.os, parent, name, 8, 1, (void *)zde, tx);
+       rc = -zap_add(o->od_os, parent, name, 8, 1, (void *)zde, tx);
 
        dmu_tx_commit(tx);
 
        *child = db->db_object;
-       sa_buf_rele(db, oi_tag);
+       sa_buf_rele(db, osd_obj_tag);
 
        return rc;
 }
@@ -212,7 +208,7 @@ osd_oi_find_or_create(const struct lu_env *env, struct osd_device *o,
  * the object is located (tgt index) and it is MDT or OST object.
  */
 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
-                  obd_seq seq, struct lu_seq_range *range)
+                  u64 seq, struct lu_seq_range *range)
 {
        struct seq_server_site  *ss = osd_seq_site(osd);
 
@@ -266,19 +262,18 @@ int fid_is_on_ost(const struct lu_env *env, struct osd_device *osd,
 }
 
 static struct osd_seq *osd_seq_find_locked(struct osd_seq_list *seq_list,
-                                          obd_seq seq)
+                                          u64 seq)
 {
        struct osd_seq *osd_seq;
 
-       cfs_list_for_each_entry(osd_seq, &seq_list->osl_seq_list, os_seq_list) {
+       list_for_each_entry(osd_seq, &seq_list->osl_seq_list, os_seq_list) {
                if (osd_seq->os_seq == seq)
                        return osd_seq;
        }
        return NULL;
 }
 
-static struct osd_seq *osd_seq_find(struct osd_seq_list *seq_list,
-                                   obd_seq seq)
+static struct osd_seq *osd_seq_find(struct osd_seq_list *seq_list, u64 seq)
 {
        struct osd_seq *osd_seq;
 
@@ -290,7 +285,7 @@ static struct osd_seq *osd_seq_find(struct osd_seq_list *seq_list,
 }
 
 static struct osd_seq *osd_find_or_add_seq(const struct lu_env *env,
-                                          struct osd_device *osd, obd_seq seq)
+                                          struct osd_device *osd, u64 seq)
 {
        struct osd_seq_list     *seq_list = &osd->od_seq_list;
        struct osd_seq          *osd_seq;
@@ -317,7 +312,7 @@ static struct osd_seq *osd_find_or_add_seq(const struct lu_env *env,
        if (osd_seq == NULL)
                GOTO(out, rc = -ENOMEM);
 
-       CFS_INIT_LIST_HEAD(&osd_seq->os_seq_list);
+       INIT_LIST_HEAD(&osd_seq->os_seq_list);
        osd_seq->os_seq = seq;
 
        /* Init subdir count to be 32, but each seq can have
@@ -349,7 +344,7 @@ static struct osd_seq *osd_find_or_add_seq(const struct lu_env *env,
        }
 
        write_lock(&seq_list->osl_seq_list_lock);
-       cfs_list_add(&osd_seq->os_seq_list, &seq_list->osl_seq_list);
+       list_add(&osd_seq->os_seq_list, &seq_list->osl_seq_list);
        write_unlock(&seq_list->osl_seq_list_lock);
 out:
        up(&seq_list->osl_seq_init_sem);
@@ -375,7 +370,7 @@ osd_get_idx_for_ost_obj(const struct lu_env *env, struct osd_device *osd,
 {
        struct osd_seq  *osd_seq;
        unsigned long   b;
-       obd_id          id;
+       u64             id;
        int             rc;
 
        osd_seq = osd_find_or_add_seq(env, osd, fid_seq(fid));
@@ -471,7 +466,7 @@ int osd_fid_lookup(const struct lu_env *env, struct osd_device *dev,
        int                     rc = 0;
        ENTRY;
 
-       if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
+       if (OBD_FAIL_CHECK(OBD_FAIL_SRV_ENOENT))
                RETURN(-ENOENT);
 
        if (unlikely(fid_is_acct(fid))) {
@@ -484,7 +479,7 @@ int osd_fid_lookup(const struct lu_env *env, struct osd_device *dev,
        } else {
                zapid = osd_get_name_n_idx(env, dev, fid, buf);
 
-               rc = -zap_lookup(dev->od_objset.os, zapid, buf,
+               rc = -zap_lookup(dev->od_os, zapid, buf,
                                8, 1, &info->oti_zde);
                if (rc)
                        RETURN(rc);
@@ -492,7 +487,7 @@ int osd_fid_lookup(const struct lu_env *env, struct osd_device *dev,
        }
 
        if (rc == 0)
-               dmu_prefetch(dev->od_objset.os, *oid, 0, 0);
+               dmu_prefetch(dev->od_os, *oid, 0, 0);
 
        RETURN(rc);
 }
@@ -509,6 +504,8 @@ osd_oi_remove_table(const struct lu_env *env, struct osd_device *o, int key)
 
        oi = o->od_oi_table[key];
        if (oi) {
+               if (oi->oi_db)
+                       sa_buf_rele(oi->oi_db, osd_obj_tag);
                OBD_FREE_PTR(oi);
                o->od_oi_table[key] = NULL;
        }
@@ -538,6 +535,7 @@ osd_oi_add_table(const struct lu_env *env, struct osd_device *o,
        }
 
        o->od_oi_table[key] = oi;
+       __osd_obj2dbuf(env, o->od_os, oi->oi_zapid, &oi->oi_db);
 
        return 0;
 }
@@ -621,24 +619,15 @@ osd_oi_probe(const struct lu_env *env, struct osd_device *o, int *count)
        RETURN(0);
 }
 
-static void osd_ost_seq_init(const struct lu_env *env, struct osd_device *osd)
-{
-       struct osd_seq_list *osl = &osd->od_seq_list;
-
-       CFS_INIT_LIST_HEAD(&osl->osl_seq_list);
-       rwlock_init(&osl->osl_seq_list_lock);
-       sema_init(&osl->osl_seq_init_sem, 1);
-}
-
 static void osd_ost_seq_fini(const struct lu_env *env, struct osd_device *osd)
 {
        struct osd_seq_list     *osl = &osd->od_seq_list;
        struct osd_seq          *osd_seq, *tmp;
 
        write_lock(&osl->osl_seq_list_lock);
-       cfs_list_for_each_entry_safe(osd_seq, tmp, &osl->osl_seq_list,
-                                    os_seq_list) {
-               cfs_list_del(&osd_seq->os_seq_list);
+       list_for_each_entry_safe(osd_seq, tmp, &osl->osl_seq_list,
+                                os_seq_list) {
+               list_del(&osd_seq->os_seq_list);
                OBD_FREE(osd_seq->os_compat_dirs,
                         sizeof(uint64_t) * osd_seq->os_subdir_count);
                OBD_FREE(osd_seq, sizeof(*osd_seq));
@@ -664,7 +653,6 @@ osd_oi_init_compat(const struct lu_env *env, struct osd_device *o)
 
        o->od_O_id = sdb;
 
-       osd_ost_seq_init(env, o);
        /* Create on-disk indexes to maintain per-UID/GID inode usage.
         * Those new indexes are created in the top-level ZAP outside the
         * namespace in order not to confuse ZPL which might interpret those
@@ -684,107 +672,6 @@ osd_oi_init_compat(const struct lu_env *env, struct osd_device *o)
        RETURN(rc);
 }
 
-static char *root2convert = "ROOT";
-/*
- * due to DNE requirements we have to change sequence of /ROOT object
- * so that it doesn't belong to the local sequence FID_SEQ_LOCAL_FILE
- * but a normal sequence living on MDS#0
- * this is the sole purpose of this function.
- *
- * This is only needed for pre-production 2.4 ZFS filesystems, and
- * can be removed in the future.
- */
-int osd_convert_root_to_new_seq(const struct lu_env *env,
-                                       struct osd_device *o)
-{
-       struct luz_direntry *lze = &osd_oti_get(env)->oti_zde;
-       char                *buf = osd_oti_get(env)->oti_str;
-       struct lu_fid        newfid;
-       uint64_t             zapid;
-       dmu_tx_t            *tx = NULL;
-       int                  rc;
-       ENTRY;
-
-       /* ignore OSTs */
-       if (strstr(o->od_svname, "MDT") == NULL)
-               RETURN(0);
-
-       /* lookup /ROOT */
-       rc = -zap_lookup(o->od_objset.os, o->od_root, root2convert, 8,
-                        sizeof(*lze) / 8, (void *)lze);
-       /* doesn't exist or let actual user to handle the error */
-       if (rc)
-               RETURN(0);
-
-       CDEBUG(D_OTHER, "%s: /ROOT -> "DFID" -> "LPU64"\n", o->od_svname,
-              PFID(&lze->lzd_fid), (long long int) lze->lzd_reg.zde_dnode);
-
-       /* already right one? */
-       if (fid_seq(&lze->lzd_fid) == FID_SEQ_ROOT)
-               return 0;
-
-       tx = dmu_tx_create(o->od_objset.os);
-       if (tx == NULL)
-               return -ENOMEM;
-
-       dmu_tx_hold_bonus(tx, o->od_root);
-
-       /* declare delete/insert of the name */
-       dmu_tx_hold_zap(tx, o->od_root, TRUE, root2convert);
-       dmu_tx_hold_zap(tx, o->od_root, FALSE, root2convert);
-
-       /* declare that we'll remove object from fid-dnode mapping */
-       zapid = osd_get_name_n_idx(env, o, &lze->lzd_fid, buf);
-       dmu_tx_hold_bonus(tx, zapid);
-       dmu_tx_hold_zap(tx, zapid, FALSE, buf);
-
-       /* declare that we'll add object to fid-dnode mapping */
-       newfid.f_seq = FID_SEQ_ROOT;
-       newfid.f_oid = 1;
-       newfid.f_ver = 0;
-       zapid = osd_get_name_n_idx(env, o, &newfid, buf);
-       dmu_tx_hold_bonus(tx, zapid);
-       dmu_tx_hold_zap(tx, zapid, TRUE, buf);
-
-       rc = -dmu_tx_assign(tx, TXG_WAIT);
-       if (rc)
-               GOTO(err, rc);
-
-       rc = -zap_remove(o->od_objset.os, o->od_root, root2convert, tx);
-       if (rc)
-               GOTO(err, rc);
-
-       /* remove from OI */
-       zapid = osd_get_name_n_idx(env, o, &lze->lzd_fid, buf);
-       rc = -zap_remove(o->od_objset.os, zapid, buf, tx);
-       if (rc)
-               GOTO(err, rc);
-
-       lze->lzd_fid = newfid;
-       rc = -zap_add(o->od_objset.os, o->od_root, root2convert,
-                     8, sizeof(*lze) / 8, (void *)lze, tx);
-       if (rc)
-               GOTO(err, rc);
-
-       /* add to OI with the new fid */
-       zapid = osd_get_name_n_idx(env, o, &newfid, buf);
-       rc = -zap_add(o->od_objset.os, zapid, buf, 8, 1, &lze->lzd_reg, tx);
-       if (rc)
-               GOTO(err, rc);
-
-
-       /* LMA will be updated in mdd_compat_fixes */
-       dmu_tx_commit(tx);
-
-       RETURN(rc);
-
-err:
-       if (tx)
-               dmu_tx_abort(tx);
-       CERROR("%s: can't convert to new fid: rc = %d\n", o->od_svname, rc);
-       RETURN(rc);
-}
-
 /**
  * Initialize the OIs by either opening or creating them as needed.
  */
@@ -862,5 +749,3 @@ int osd_options_init(void)
 
        return 0;
 }
-
-