Whamcloud - gitweb
LU-8130 lov: convert lo[v|d]_pool to use rhashtable
[fs/lustre-release.git] / lustre / lov / lov_obd.c
index 45c57fc..a66b697 100644 (file)
@@ -57,7 +57,7 @@
 
 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
    Any function that expects lov_tgts to remain stationary must take a ref. */
-static void lov_getref(struct obd_device *obd)
+void lov_tgts_getref(struct obd_device *obd)
 {
        struct lov_obd *lov = &obd->u.lov;
 
@@ -65,19 +65,18 @@ static void lov_getref(struct obd_device *obd)
        mutex_lock(&lov->lov_lock);
        atomic_inc(&lov->lov_refcount);
        mutex_unlock(&lov->lov_lock);
-       return;
 }
 
 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt);
 
-static void lov_putref(struct obd_device *obd)
+void lov_tgts_putref(struct obd_device *obd)
 {
        struct lov_obd *lov = &obd->u.lov;
 
        mutex_lock(&lov->lov_lock);
        /* ok to dec to 0 more than once -- ltd_exp's will be null */
        if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
-               struct list_head kill = LIST_HEAD_INIT(kill);
+               LIST_HEAD(kill);
                struct lov_tgt_desc *tgt, *n;
                int i;
 
@@ -113,7 +112,7 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                      enum obd_notify_event ev);
 
-int lov_connect_obd(struct obd_device *obd, u32 index, int activate,
+int lov_connect_osc(struct obd_device *obd, u32 index, int activate,
                    struct obd_connect_data *data)
 {
        struct lov_obd *lov = &obd->u.lov;
@@ -146,12 +145,12 @@ int lov_connect_obd(struct obd_device *obd, u32 index, int activate,
          */
         imp = tgt_obd->u.cli.cl_import;
 
-        if (activate) {
-                tgt_obd->obd_no_recov = 0;
-                /* FIXME this is probably supposed to be
-                   ptlrpc_set_import_active.  Horrible naming. */
-                ptlrpc_activate_import(imp);
-        }
+       if (activate) {
+               tgt_obd->obd_no_recov = 0;
+               /* FIXME this is probably supposed to be
+                  ptlrpc_set_import_active.  Horrible naming. */
+               ptlrpc_activate_import(imp, false);
+       }
 
         rc = obd_register_observer(tgt_obd, obd);
         if (rc) {
@@ -160,15 +159,14 @@ int lov_connect_obd(struct obd_device *obd, u32 index, int activate,
                 RETURN(rc);
         }
 
+       if (imp->imp_invalid) {
+               CDEBUG(D_CONFIG, "%s: not connecting - administratively disabled\n",
+                      obd_uuid2str(tgt_uuid));
+               RETURN(0);
+       }
 
-        if (imp->imp_invalid) {
-                CDEBUG(D_CONFIG, "not connecting OSC %s; administratively "
-                       "disabled\n", obd_uuid2str(tgt_uuid));
-                RETURN(0);
-        }
-
-        rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
-                         &lov_osc_uuid, data, NULL);
+       rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
+                        &lov_osc_uuid, data, lov->lov_cache);
         if (rc || !lov->lov_tgts[index]->ltd_exp) {
                 CERROR("Target %s connect error %d\n",
                        obd_uuid2str(tgt_uuid), rc);
@@ -223,14 +221,19 @@ static int lov_connect(const struct lu_env *env,
         if (data)
                 lov->lov_ocd = *data;
 
-       obd_getref(obd);
+       lov_tgts_getref(obd);
 
-        for (i = 0; i < lov->desc.ld_tgt_count; i++) {
-                tgt = lov->lov_tgts[i];
-                if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
-                        continue;
-                /* Flags will be lowest common denominator */
-                rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
+       if (localdata) {
+               lov->lov_cache = localdata;
+               cl_cache_incref(lov->lov_cache);
+       }
+
+       for (i = 0; i < lov->desc.ld_tgt_count; i++) {
+               tgt = lov->lov_tgts[i];
+               if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
+                       continue;
+               /* Flags will be lowest common denominator */
+               rc = lov_connect_osc(obd, i, tgt->ltd_activate, &lov->lov_ocd);
                 if (rc) {
                         CERROR("%s: lov connect tgt %d failed: %d\n",
                                obd->obd_name, i, rc);
@@ -247,9 +250,10 @@ static int lov_connect(const struct lu_env *env,
                                obd->obd_name, rc);
                 }
         }
-        obd_putref(obd);
 
-        RETURN(0);
+       lov_tgts_putref(obd);
+
+       RETURN(0);
 }
 
 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
@@ -321,7 +325,7 @@ static int lov_disconnect(struct obd_export *exp)
        }
 
        /* hold another ref so lov_del_obd() doesn't spin in putref each time */
-       obd_getref(obd);
+       lov_tgts_getref(obd);
 
        for (index = 0; index < lov->desc.ld_tgt_count; index++) {
                if (lov->lov_tgts[index] && lov->lov_tgts[index]->ltd_exp) {
@@ -330,7 +334,7 @@ static int lov_disconnect(struct obd_export *exp)
                                       lov->lov_tgts[index]->ltd_gen);
                }
        }
-       obd_putref(obd);
+       lov_tgts_putref(obd);
 
 out:
        rc = class_disconnect(exp); /* bz 9811 */
@@ -355,30 +359,13 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
         CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
                lov, uuid->uuid, ev);
 
-       obd_getref(obd);
+       lov_tgts_getref(obd);
        for (index = 0; index < lov->desc.ld_tgt_count; index++) {
                tgt = lov->lov_tgts[index];
                if (!tgt)
                        continue;
-               /*
-                * LU-642, initially inactive OSC could miss the obd_connect,
-                * we make up for it here.
-                */
-               if (ev == OBD_NOTIFY_ACTIVATE && tgt->ltd_exp == NULL &&
-                   obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
-                       struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
-
-                       obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
-                                   &lov_osc_uuid, &lov->lov_ocd, NULL);
-               }
-               if (!tgt->ltd_exp)
-                       continue;
-
-               CDEBUG(D_INFO, "lov idx %d is %s conn %#llx\n",
-                       index, obd_uuid2str(&tgt->ltd_uuid),
-                       tgt->ltd_exp->exp_handle.h_cookie);
-                if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
-                        break;
+               if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
+                       break;
         }
 
         if (index == lov->desc.ld_tgt_count)
@@ -387,6 +374,21 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
         if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
                 activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0;
 
+               /*
+                * LU-642, initially inactive OSC could miss the obd_connect,
+                * we make up for it here.
+                */
+               if (activate && !tgt->ltd_exp) {
+                       int rc;
+                       struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
+
+                       rc = obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
+                                        &lov_osc_uuid, &lov->lov_ocd,
+                                        lov->lov_cache);
+                       if (rc || tgt->ltd_exp == NULL)
+                               GOTO(out, index = rc);
+               }
+
                 if (lov->lov_tgts[index]->ltd_activate == activate) {
                         CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
                                uuid->uuid, activate ? "" : "de");
@@ -421,8 +423,12 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
                       ev, uuid->uuid);
        }
 
+       if (tgt->ltd_exp)
+               CDEBUG(D_INFO, "%s: lov idx %d conn %llx\n", obd_uuid2str(uuid),
+                      index, tgt->ltd_exp->exp_handle.h_cookie);
+
  out:
-       obd_putref(obd);
+       lov_tgts_putref(obd);
        RETURN(index);
 }
 
@@ -563,16 +569,16 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
         CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
                 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
 
-        if (lov->lov_connects == 0) {
-                /* lov_connect hasn't been called yet. We'll do the
-                   lov_connect_obd on this target when that fn first runs,
-                   because we don't know the connect flags yet. */
-                RETURN(0);
-        }
+       if (lov->lov_connects == 0) {
+               /* lov_connect hasn't been called yet. We'll do the
+                  lov_connect_osc on this target when that fn first runs,
+                  because we don't know the connect flags yet. */
+               RETURN(0);
+       }
 
-        obd_getref(obd);
+       lov_tgts_getref(obd);
 
-        rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
+       rc = lov_connect_osc(obd, index, active, &lov->lov_ocd);
         if (rc)
                 GOTO(out, rc);
 
@@ -580,15 +586,6 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
         if (!tgt->ltd_exp)
                 GOTO(out, rc = 0);
 
-       if (lov->lov_cache != NULL) {
-               rc = obd_set_info_async(NULL, tgt->ltd_exp,
-                               sizeof(KEY_CACHE_SET), KEY_CACHE_SET,
-                               sizeof(struct cl_client_cache), lov->lov_cache,
-                               NULL);
-               if (rc < 0)
-                       GOTO(out, rc);
-       }
-
        rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
                        active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE);
 
@@ -598,7 +595,7 @@ out:
                       obd->obd_name, obd_uuid2str(&tgt->ltd_uuid), rc);
                lov_del_target(obd, index, NULL, 0);
        }
-       obd_putref(obd);
+       lov_tgts_putref(obd);
        RETURN(rc);
 }
 
@@ -619,7 +616,7 @@ int lov_del_target(struct obd_device *obd, u32 index,
 
        /* to make sure there's no ongoing lov_notify() now */
        down_write(&lov->lov_notify_lock);
-        obd_getref(obd);
+       lov_tgts_getref(obd);
 
         if (!lov->lov_tgts[index]) {
                 CERROR("LOV target at index %d is not setup.\n", index);
@@ -640,12 +637,12 @@ int lov_del_target(struct obd_device *obd, u32 index,
 
         lov->lov_tgts[index]->ltd_reap = 1;
         lov->lov_death_row++;
-        /* we really delete it from obd_putref */
+       /* we really delete it from lov_tgts_putref() */
 out:
-        obd_putref(obd);
+       lov_tgts_putref(obd);
        up_write(&lov->lov_notify_lock);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
@@ -698,10 +695,10 @@ void lov_fix_desc_stripe_count(__u32 *val)
 void lov_fix_desc_pattern(__u32 *val)
 {
         /* from lov_setstripe */
-        if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
-                LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
-                *val = 0;
-        }
+       if ((*val != 0) && !lov_pattern_supported_normal_comp(*val)) {
+               LCONSOLE_WARN("lov: Unknown stripe pattern: %#x\n", *val);
+               *val = 0;
+       }
 }
 
 void lov_fix_desc_qos_maxage(__u32 *val)
@@ -762,15 +759,12 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
        init_rwsem(&lov->lov_notify_lock);
 
-        lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
-                                                   HASH_POOLS_MAX_BITS,
-                                                   HASH_POOLS_BKT_BITS, 0,
-                                                   CFS_HASH_MIN_THETA,
-                                                   CFS_HASH_MAX_THETA,
-                                                   &pool_hash_operations,
-                                                   CFS_HASH_DEFAULT);
        INIT_LIST_HEAD(&lov->lov_pool_list);
         lov->lov_pool_count = 0;
+       rc = lov_pool_hash_init(&lov->lov_pools_hash_body);
+       if (rc)
+               GOTO(out, rc);
+
         rc = lov_ost_pool_init(&lov->lov_packed, 0);
         if (rc)
                GOTO(out, rc);
@@ -807,13 +801,13 @@ static int lov_cleanup(struct obd_device *obd)
                /* coverity[overrun-buffer-val] */
                 lov_pool_del(obd, pool->pool_name);
         }
-        cfs_hash_putref(lov->lov_pools_hash_body);
+       lov_pool_hash_destroy(&lov->lov_pools_hash_body);
         lov_ost_pool_free(&lov->lov_packed);
 
        lprocfs_obd_cleanup(obd);
         if (lov->lov_tgts) {
                 int i;
-                obd_getref(obd);
+               lov_tgts_getref(obd);
                 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                        if (!lov->lov_tgts[i])
                                continue;
@@ -830,7 +824,7 @@ static int lov_cleanup(struct obd_device *obd)
                                       atomic_read(&lov->lov_refcount));
                        lov_del_target(obd, i, NULL, 0);
                }
-                obd_putref(obd);
+               lov_tgts_putref(obd);
                 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
                          lov->lov_tgt_size);
                 lov->lov_tgt_size = 0;
@@ -944,7 +938,7 @@ static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
                        GOTO(out_set, rc);
        }
 
-       rc = ptlrpc_set_wait(rqset);
+       rc = ptlrpc_set_wait(env, rqset);
 
 out_set:
        if (rc < 0)
@@ -963,14 +957,14 @@ out_rqset:
 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         void *karg, void __user *uarg)
 {
-        struct obd_device *obddev = class_exp2obd(exp);
-        struct lov_obd *lov = &obddev->u.lov;
-        int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
-        struct obd_uuid *uuidp;
-        ENTRY;
+       struct obd_device *obd = class_exp2obd(exp);
+       struct lov_obd *lov = &obd->u.lov;
+       int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
+       struct obd_uuid *uuidp;
 
-        switch (cmd) {
-        case IOC_OBD_STATFS: {
+       ENTRY;
+       switch (cmd) {
+       case IOC_OBD_STATFS: {
                struct obd_ioctl_data *data = karg;
                struct obd_device *osc_obd;
                struct obd_statfs stat_buf = {0};
@@ -979,21 +973,22 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                __u32 flags;
 
                memcpy(&index, data->ioc_inlbuf2, sizeof(index));
-               if ((index >= count))
+               if (index >= count)
                        RETURN(-ENODEV);
 
                if (!lov->lov_tgts[index])
                        /* Try again with the next index */
                        RETURN(-EAGAIN);
-               imp = lov->lov_tgts[index]->ltd_exp->exp_obd->u.cli.cl_import;
-               if (!lov->lov_tgts[index]->ltd_active &&
-                   imp->imp_state != LUSTRE_IMP_IDLE)
-                       RETURN(-ENODATA);
 
                osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
                if (!osc_obd)
                        RETURN(-EINVAL);
 
+               imp = osc_obd->u.cli.cl_import;
+               if (!lov->lov_tgts[index]->ltd_active &&
+                   imp->imp_state != LUSTRE_IMP_IDLE)
+                       RETURN(-ENODATA);
+
                /* copy UUID */
                if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
                                 min_t(unsigned long, data->ioc_plen2,
@@ -1003,12 +998,12 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                memcpy(&flags, data->ioc_inlbuf1, sizeof(flags));
                flags = flags & LL_STATFS_NODELAY ? OBD_STATFS_NODELAY : 0;
 
-                /* got statfs data */
-                rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf,
+               /* got statfs data */
+               rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf,
                                ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
-                                flags);
-                if (rc)
-                        RETURN(rc);
+                               flags);
+               if (rc)
+                       RETURN(rc);
                if (copy_to_user(data->ioc_pbuf1, &stat_buf,
                                 min_t(unsigned long, data->ioc_plen1,
                                       sizeof(struct obd_statfs))))
@@ -1121,12 +1116,11 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
                                 continue;
 
-                        /* ll_umount_begin() sets force flag but for lov, not
-                         * osc. Let's pass it through */
-                        osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
-                        osc_obd->obd_force = obddev->obd_force;
-                        err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
-                                            len, karg, uarg);
+                       /* ll_umount_begin() sets force on lov, pass to osc */
+                       osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
+                       osc_obd->obd_force = obd->obd_force;
+                       err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
+                                           len, karg, uarg);
                        if (err) {
                                 if (lov->lov_tgts[i]->ltd_active) {
                                         CDEBUG(err == -ENOTTY ?
@@ -1162,13 +1156,10 @@ static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
        if (vallen == NULL || val == NULL)
                RETURN(-EFAULT);
 
-       obd_getref(obddev);
+       lov_tgts_getref(obddev);
 
        if (KEY_IS(KEY_MAX_EASIZE)) {
-               u32 max_stripe_count = min_t(u32, ld->ld_active_tgt_count,
-                                            LOV_MAX_STRIPE_COUNT);
-
-               *((u32 *)val) = lov_mds_md_size(max_stripe_count, LOV_MAGIC_V3);
+               *((u32 *)val) = exp->exp_connect_data.ocd_max_easize;
        } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
                u32 def_stripe_count = min_t(u32, ld->ld_default_stripe_count,
                                             LOV_MAX_STRIPE_COUNT);
@@ -1180,7 +1171,7 @@ static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
                rc = -EINVAL;
        }
 
-       obd_putref(obddev);
+       lov_tgts_putref(obddev);
 
        RETURN(rc);
 }
@@ -1207,16 +1198,10 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                        RETURN(-ENOMEM);
        }
 
-       obd_getref(obddev);
+       lov_tgts_getref(obddev);
 
-       if (KEY_IS(KEY_CHECKSUM)) {
-               do_inactive = true;
-       } else if (KEY_IS(KEY_CACHE_SET)) {
-               LASSERT(lov->lov_cache == NULL);
-               lov->lov_cache = val;
+       if (KEY_IS(KEY_CHECKSUM))
                do_inactive = true;
-               cl_cache_incref(lov->lov_cache);
-       }
 
        for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                tgt = lov->lov_tgts[i];
@@ -1250,9 +1235,9 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                        rc = err;
        }
 
-       obd_putref(obddev);
+       lov_tgts_putref(obddev);
        if (no_set) {
-               err = ptlrpc_set_wait(set);
+               err = ptlrpc_set_wait(env, set);
                if (rc == 0)
                        rc = err;
                ptlrpc_set_destroy(set);
@@ -1295,7 +1280,7 @@ static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
        }
 
         /* for lov tgt */
-        obd_getref(obd);
+       lov_tgts_getref(obd);
         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                 int err;
 
@@ -1327,7 +1312,7 @@ static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
                         bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
                 }
         }
-        obd_putref(obd);
+       lov_tgts_putref(obd);
 
         if (oqctl->qc_cmd == Q_GETOQUOTA) {
                 oqctl->qc_dqblk.dqb_curspace = curspace;
@@ -1336,7 +1321,7 @@ static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
         RETURN(rc);
 }
 
-static struct obd_ops lov_obd_ops = {
+static const struct obd_ops lov_obd_ops = {
        .o_owner                = THIS_MODULE,
        .o_setup                = lov_setup,
        .o_cleanup              = lov_cleanup,
@@ -1351,8 +1336,6 @@ static struct obd_ops lov_obd_ops = {
        .o_pool_rem             = lov_pool_remove,
        .o_pool_add             = lov_pool_add,
        .o_pool_del             = lov_pool_del,
-       .o_getref               = lov_getref,
-       .o_putref               = lov_putref,
        .o_quotactl             = lov_quotactl,
 };
 
@@ -1360,8 +1343,6 @@ struct kmem_cache *lov_oinfo_slab;
 
 static int __init lov_init(void)
 {
-       bool enable_proc = true;
-       struct obd_type *type;
        int rc;
        ENTRY;
 
@@ -1382,13 +1363,8 @@ static int __init lov_init(void)
                 return -ENOMEM;
         }
 
-       type = class_search_type(LUSTRE_LOD_NAME);
-       if (type != NULL && type->typ_procsym != NULL)
-               enable_proc = false;
-
-       rc = class_register_type(&lov_obd_ops, NULL, enable_proc, NULL,
+       rc = class_register_type(&lov_obd_ops, NULL, true, NULL,
                                 LUSTRE_LOV_NAME, &lov_device_type);
-
         if (rc) {
                kmem_cache_destroy(lov_oinfo_slab);
                 lu_kmem_fini(lov_caches);