Whamcloud - gitweb
LU-8119 osd: remove dcb entry from the list prior processing.
[fs/lustre-release.git] / lustre / osd-zfs / osd_handler.c
index 3f7816b..9c09620 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -147,8 +147,13 @@ static void osd_trans_commit_cb(void *cb_data, int error)
        dt_txn_hook_commit(th);
 
        /* call per-transaction callbacks if any */
-       list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage)
+       list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
+               LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
+                        "commit callback entry: magic=%x name='%s'\n",
+                        dcb->dcb_magic, dcb->dcb_name);
+               list_del_init(&dcb->dcb_linkage);
                dcb->dcb_func(NULL, th, dcb, error);
+       }
 
        /* Unlike ldiskfs, zfs updates space accounting at commit time.
         * As a consequence, op_end is called only now to inform the quota slave
@@ -238,8 +243,8 @@ static void osd_unlinked_list_emptify(struct osd_device *osd,
        while (!list_empty(list)) {
                obj = list_entry(list->next,
                                 struct osd_object, oo_unlinked_linkage);
-               LASSERT(obj->oo_db != NULL);
-               oid = obj->oo_db->db_object;
+               LASSERT(obj->oo_dn != NULL);
+               oid = obj->oo_dn->dn_object;
 
                list_del_init(&obj->oo_unlinked_linkage);
                if (free)
@@ -280,6 +285,8 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
        oh = container_of0(th, struct osd_thandle, ot_super);
        INIT_LIST_HEAD(&unlinked);
        list_splice_init(&oh->ot_unlinked_list, &unlinked);
+       /* reset OI cache for safety */
+       osd_oti_get(env)->oti_ins_cache_used = 0;
 
        if (oh->ot_assigned == 0) {
                LASSERT(oh->ot_tx);
@@ -293,16 +300,6 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
                RETURN(0);
        }
 
-       /* When doing our own inode accounting, the ZAPs storing per-uid/gid
-        * usage are updated at operation execution time, so we should call
-        * qsd_op_end() straight away. Otherwise (for blk accounting maintained
-        * by ZFS and when #inode is estimated from #blks) accounting is updated
-        * at commit time and the call to qsd_op_end() must be delayed */
-       if (oh->ot_quota_trans.lqt_id_cnt > 0 &&
-                       !oh->ot_quota_trans.lqt_ids[0].lqi_is_blk &&
-                       !osd->od_quota_iused_est)
-               qsd_op_end(env, osd->od_quota_slave, &oh->ot_quota_trans);
-
        rc = dt_txn_hook_stop(env, th);
        if (rc != 0)
                CDEBUG(D_OTHER, "%s: transaction hook failed: rc = %d\n",
@@ -335,6 +332,14 @@ static struct thandle *osd_trans_create(const struct lu_env *env,
        dmu_tx_t                *tx;
        ENTRY;
 
+       if (dt->dd_rdonly) {
+               CERROR("%s: someone try to start transaction under "
+                      "readonly mode, should be disabled.\n",
+                      osd_name(osd_dt_dev(dt)));
+               dump_stack();
+               RETURN(ERR_PTR(-EROFS));
+       }
+
        tx = dmu_tx_create(osd->od_os);
        if (tx == NULL)
                RETURN(ERR_PTR(-ENOMEM));
@@ -392,9 +397,9 @@ uint64_t osd_objs_count_estimate(uint64_t usedbytes, uint64_t usedobjs,
        CLASSERT(OSD_DNODE_MIN_BLKSHIFT > 0);
        CLASSERT(OSD_DNODE_EST_BLKSHIFT > 0);
 
-       est_usedblocks = (usedbytes >> est_maxblockshift) +
-                        (OSD_DNODE_EST_COUNT >> OSD_DNODE_EST_BLKSHIFT);
-       est_usedobjs   = usedobjs + OSD_DNODE_EST_COUNT;
+       est_usedblocks = ((OSD_DNODE_EST_COUNT << OSD_DNODE_EST_BLKSHIFT) +
+                         usedbytes) >> est_maxblockshift;
+       est_usedobjs   = OSD_DNODE_EST_COUNT + usedobjs;
 
        if (est_usedobjs <= est_usedblocks) {
                /*
@@ -479,7 +484,8 @@ static int osd_objset_statfs(struct osd_device *osd, struct obd_statfs *osfs)
        osfs->os_bavail = osfs->os_bfree; /* no extra root reservation */
 
        /* Take replication (i.e. number of copies) into account */
-       osfs->os_bavail /= os->os_copies;
+       if (os->os_copies != 0)
+               osfs->os_bavail /= os->os_copies;
 
        /*
         * Reserve some space so we don't run into ENOSPC due to grants not
@@ -613,10 +619,14 @@ static void osd_conf_get(const struct lu_env *env,
  */
 static int osd_sync(const struct lu_env *env, struct dt_device *d)
 {
-       struct osd_device  *osd = osd_dt_dev(d);
-       CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_ZFS_NAME);
-       txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
-       CDEBUG(D_CACHE, "synced OSD %s\n", LUSTRE_OSD_ZFS_NAME);
+       if (!d->dd_rdonly) {
+               struct osd_device  *osd = osd_dt_dev(d);
+
+               CDEBUG(D_CACHE, "syncing OSD %s\n", LUSTRE_OSD_ZFS_NAME);
+               txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
+               CDEBUG(D_CACHE, "synced OSD %s\n", LUSTRE_OSD_ZFS_NAME);
+       }
+
        return 0;
 }
 
@@ -697,16 +707,20 @@ static void osd_key_fini(const struct lu_context *ctx,
                         struct lu_context_key *key, void *data)
 {
        struct osd_thread_info *info = data;
+       struct osd_idmap_cache *idc = info->oti_ins_cache;
 
+       if (idc != NULL) {
+               LASSERT(info->oti_ins_cache_size > 0);
+               OBD_FREE(idc, sizeof(*idc) * info->oti_ins_cache_size);
+               info->oti_ins_cache = NULL;
+               info->oti_ins_cache_size = 0;
+       }
        OBD_FREE_PTR(info);
 }
 
 static void osd_key_exit(const struct lu_context *ctx,
                         struct lu_context_key *key, void *data)
 {
-       struct osd_thread_info *info = data;
-
-       memset(info, 0, sizeof(*info));
 }
 
 struct lu_context_key osd_key = {
@@ -833,11 +847,14 @@ static int osd_objset_open(struct osd_device *o)
        int             rc;
        ENTRY;
 
-       rc = -dmu_objset_own(o->od_mntdev, DMU_OST_ZFS, B_FALSE, o, &o->od_os);
+       rc = -dmu_objset_own(o->od_mntdev, DMU_OST_ZFS,
+                            o->od_dt_dev.dd_rdonly ? B_TRUE : B_FALSE,
+                            o, &o->od_os);
        if (rc) {
                CERROR("%s: can't open %s\n", o->od_svname, o->od_mntdev);
                o->od_os = NULL;
-               goto out;
+
+               GOTO(out, rc);
        }
 
        /* Check ZFS version */
@@ -884,7 +901,7 @@ static int osd_objset_open(struct osd_device *o)
            DMU_GROUPUSED_DNODE(o->od_os)->dn_type != DMU_OT_USERGROUP_USED) {
                CERROR("%s: Space accounting not supported by this target, "
                        "aborting\n", o->od_svname);
-               GOTO(out, -ENOTSUPP);
+               GOTO(out, rc = -ENOTSUPP);
        }
 
 out:
@@ -902,6 +919,14 @@ osd_unlinked_object_free(struct osd_device *osd, uint64_t oid)
        int       rc;
        dmu_tx_t *tx;
 
+       if (osd->od_dt_dev.dd_rdonly) {
+               CERROR("%s: someone try to free objects under "
+                      "readonly mode, should be disabled.\n", osd_name(osd));
+               dump_stack();
+
+               return -EROFS;
+       }
+
        rc = -dmu_free_long_range(osd->od_os, oid, 0, DMU_OBJECT_END);
        if (rc != 0) {
                CWARN("%s: Cannot truncate %llu: rc = %d\n",
@@ -967,8 +992,9 @@ static int osd_mount(const struct lu_env *env,
                     struct osd_device *o, struct lustre_cfg *cfg)
 {
        char                    *mntdev = lustre_cfg_string(cfg, 1);
+       char                    *str    = lustre_cfg_string(cfg, 2);
        char                    *svname = lustre_cfg_string(cfg, 4);
-       dmu_buf_t               *rootdb;
+       dnode_t *rootdn;
        const char              *opts;
        int                      rc;
        ENTRY;
@@ -987,6 +1013,21 @@ static int osd_mount(const struct lu_env *env,
        if (rc >= sizeof(o->od_svname))
                RETURN(-E2BIG);
 
+       str = strstr(str, ":");
+       if (str) {
+               unsigned long flags;
+
+               rc = kstrtoul(str + 1, 10, &flags);
+               if (rc)
+                       RETURN(-EINVAL);
+
+               if (flags & LMD_FLG_DEV_RDONLY) {
+                       o->od_dt_dev.dd_rdonly = 1;
+                       LCONSOLE_WARN("%s: set dev_rdonly on this device\n",
+                                     svname);
+               }
+       }
+
        if (server_name_is_ost(o->od_svname))
                o->od_is_ost = 1;
 
@@ -1001,12 +1042,12 @@ static int osd_mount(const struct lu_env *env,
        if (rc)
                GOTO(err, rc);
 
-       rc = __osd_obj2dbuf(env, o->od_os, o->od_rootid, &rootdb);
+       rc = __osd_obj2dnode(env, o->od_os, o->od_rootid, &rootdn);
        if (rc)
                GOTO(err, rc);
 
-       o->od_root = rootdb->db_object;
-       sa_buf_rele(rootdb, osd_obj_tag);
+       o->od_root = rootdn->dn_object;
+       osd_dnode_rele(rootdn);
 
        /* 1. initialize oi before any file create or file open */
        rc = osd_oi_init(env, o);
@@ -1022,10 +1063,6 @@ static int osd_mount(const struct lu_env *env,
        if (rc)
                GOTO(err, rc);
 
-       /* Use our own ZAP for inode accounting by default, this can be changed
-        * via procfs to estimate the inode usage from the block usage */
-       o->od_quota_iused_est = 0;
-
        rc = osd_procfs_init(o, o->od_svname);
        if (rc)
                GOTO(err, rc);
@@ -1046,7 +1083,7 @@ static int osd_mount(const struct lu_env *env,
 
        osd_unlinked_drain(env, o);
 err:
-       if (rc) {
+       if (rc && o->od_os) {
                dmu_objset_disown(o->od_os, o);
                o->od_os = NULL;
        }
@@ -1069,8 +1106,9 @@ static void osd_umount(const struct lu_env *env, struct osd_device *o)
                       atomic_read(&o->od_zerocopy_pin));
 
        if (o->od_os != NULL) {
-               /* force a txg sync to get all commit callbacks */
-               txg_wait_synced(dmu_objset_pool(o->od_os), 0ULL);
+               if (!o->od_dt_dev.dd_rdonly)
+                       /* force a txg sync to get all commit callbacks */
+                       txg_wait_synced(dmu_objset_pool(o->od_os), 0ULL);
 
                /* close the object set */
                dmu_objset_disown(o->od_os, o);
@@ -1171,8 +1209,11 @@ static struct lu_device *osd_device_fini(const struct lu_env *env,
 
        if (o->od_os) {
                osd_objset_unregister_callbacks(o);
-               osd_sync(env, lu2dt_dev(d));
-               txg_wait_callbacks(spa_get_dsl(dmu_objset_spa(o->od_os)));
+               if (!o->od_dt_dev.dd_rdonly) {
+                       osd_sync(env, lu2dt_dev(d));
+                       txg_wait_callbacks(
+                                       spa_get_dsl(dmu_objset_spa(o->od_os)));
+               }
        }
 
        rc = osd_procfs_fini(o);