Whamcloud - gitweb
LU-10341 hsm: filter kkuc write by client UUID 19/30719/2
authorJohn L. Hammond <john.hammond@intel.com>
Thu, 7 Dec 2017 02:21:48 +0000 (20:21 -0600)
committerJohn L. Hammond <john.hammond@intel.com>
Fri, 9 Feb 2018 16:57:53 +0000 (16:57 +0000)
Add a struct obd_uuid kr_uuid member to struct kkuc_reg to hold the
UUID of the client (super block) that owns the kkuc pipe. Modify
libcfs_kkuc_group_{put,rem,foreach}() to accept a UUID pointer which
filters the kkuc pipes operated on. Modify mdc_hsm_copytool_send() to
pass the UUID of the MDC device when calling
libcfs_kkuc_group_put(). The effect of all this is that HALs received
by a given MDC will only be delivered to copytools registered on the
corresponding mount point.

Remove the cluuid member of struct lmv_obd since it is always the same
as the obd_uuid member of the corresponding struct obd_device. Remove
the kcd_uuid member of struct kkuc_ct_data as it is no longer needed.

Lustre-change: https://review.whamcloud.com/30419
Lustre-commit: c73736545fafac4373569187e064aab9cd435320

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Ibbda253979739a1d56d3e132a51a482a02a0ec27
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Faccini Bruno <bruno.faccini@intel.com>
Signed-off-by: Minh Diep <minh.diep@intel.com>
Reviewed-on: https://review.whamcloud.com/30719
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
lustre/include/lustre_export.h
lustre/include/lustre_kernelcomm.h
lustre/include/obd.h
lustre/lmv/lmv_obd.c
lustre/mdc/mdc_request.c
lustre/obdclass/kernelcomm.c

index 7299b68..8552d3d 100644 (file)
@@ -426,7 +426,6 @@ extern struct obd_device *class_conn2obd(struct lustre_handle *conn);
 #define KKUC_CT_DATA_MAGIC     0x092013cea
 struct kkuc_ct_data {
        __u32           kcd_magic;
-       struct obd_uuid kcd_uuid;
        __u32           kcd_archive;
 };
 
index cb8a29f..4fc7656 100644 (file)
@@ -46,12 +46,12 @@ typedef int (*libcfs_kkuc_cb_t)(void *data, void *cb_arg);
 /* Kernel methods */
 void libcfs_kkuc_init(void);
 int libcfs_kkuc_msg_put(struct file *fp, void *payload);
-int libcfs_kkuc_group_put(int group, void *payload);
-int libcfs_kkuc_group_add(struct file *fp, int uid, int group,
-                         void *data, size_t data_len);
-int libcfs_kkuc_group_rem(int uid, int group);
-int libcfs_kkuc_group_foreach(int group, libcfs_kkuc_cb_t cb_func,
-                             void *cb_arg);
+int libcfs_kkuc_group_put(const struct obd_uuid *uuid, int group, void *data);
+int libcfs_kkuc_group_add(struct file *fp, const struct obd_uuid *uuid, int uid,
+                         int group, void *data, size_t data_len);
+int libcfs_kkuc_group_rem(const struct obd_uuid *uuid, int uid, int group);
+int libcfs_kkuc_group_foreach(const struct obd_uuid *uuid, int group,
+                             libcfs_kkuc_cb_t cb_func, void *cb_arg);
 
 #endif /* __LUSTRE_KERNELCOMM_H__ */
 
index 007fc59..ba31e45 100644 (file)
@@ -407,7 +407,6 @@ struct lmv_obd {
        struct lu_client_fld    lmv_fld;
        spinlock_t              lmv_lock;
        struct lmv_desc         desc;
-       struct obd_uuid         cluuid;
        struct proc_dir_entry   *targets_proc_entry;
 
        struct mutex            lmv_init_mutex;
index 8364def..3fed10f 100644 (file)
@@ -211,7 +211,6 @@ static int lmv_connect(const struct lu_env *env,
        exp = class_conn2export(&conn);
 
        lmv->connected = 0;
-       lmv->cluuid = *cluuid;
        lmv->conn_data = *data;
 
        if (lmv->targets_proc_entry == NULL) {
@@ -292,8 +291,6 @@ static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
 {
         struct lmv_obd          *lmv = &obd->u.lmv;
-        struct obd_uuid         *cluuid = &lmv->cluuid;
-        struct obd_uuid          lmv_mdc_uuid = { "LMV_MDC_UUID" };
         struct obd_device       *mdc_obd;
         struct obd_export       *mdc_exp;
         struct lu_fld_target     target;
@@ -307,18 +304,17 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
                 RETURN(-EINVAL);
         }
 
-        CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
-                mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
-                tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
-                cluuid->uuid);
+       CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s\n",
+              mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
+              tgt->ltd_uuid.uuid, obd->obd_uuid.uuid);
 
         if (!mdc_obd->obd_set_up) {
                 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
                 RETURN(-EINVAL);
         }
 
-        rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
-                         &lmv->conn_data, NULL);
+       rc = obd_connect(NULL, &mdc_exp, mdc_obd, &obd->obd_uuid,
+                        &lmv->conn_data, NULL);
         if (rc) {
                 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
                 RETURN(rc);
@@ -531,7 +527,7 @@ static int lmv_check_connect(struct obd_device *obd)
        }
 
        CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
-              lmv->cluuid.uuid, obd->obd_name);
+              obd->obd_uuid.uuid, obd->obd_name);
 
        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                tgt = lmv->tgts[i];
@@ -789,10 +785,11 @@ static int lmv_hsm_req_build(struct lmv_obd *lmv,
        RETURN(0);
 }
 
-static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
-                                struct lustre_kernelcomm *lk,
+static int lmv_hsm_ct_unregister(struct obd_device *obd, unsigned int cmd,
+                                int len, struct lustre_kernelcomm *lk,
                                 void __user *uarg)
 {
+       struct lmv_obd *lmv = &obd->u.lmv;
        __u32   i;
        int     rc;
        ENTRY;
@@ -812,22 +809,23 @@ static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
         * Unreached coordinators will get EPIPE on next requests
         * and will unregister automatically.
         */
-       rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
+       rc = libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
 
        RETURN(rc);
 }
 
-static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
-                              struct lustre_kernelcomm *lk, __user void *uarg)
+static int lmv_hsm_ct_register(struct obd_device *obd, unsigned int cmd,
+                              int len, struct lustre_kernelcomm *lk,
+                              void __user *uarg)
 {
+       struct lmv_obd *lmv = &obd->u.lmv;
        struct file             *filp;
        __u32                    i, j;
        int                      err;
        bool                     any_set = false;
        struct kkuc_ct_data      kcd = {
                .kcd_magic   = KKUC_CT_DATA_MAGIC,
-               .kcd_uuid    = lmv->cluuid,
-               .kcd_archive = lk->lk_data
+               .kcd_archive = lk->lk_data,
        };
        int                      rc = 0;
        ENTRY;
@@ -836,8 +834,8 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
        if (!filp)
                RETURN(-EBADF);
 
-       rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
-                                  &kcd, sizeof(kcd));
+       rc = libcfs_kkuc_group_add(filp, &obd->obd_uuid, lk->lk_uid,
+                                  lk->lk_group, &kcd, sizeof(kcd));
        if (rc)
                GOTO(err_fput, rc);
 
@@ -885,7 +883,7 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
        RETURN(0);
 
 err_kkuc_rem:
-       libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
+       libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
 
 err_fput:
        fput(filp);
@@ -1119,9 +1117,9 @@ hsm_req_err:
        case LL_IOC_HSM_CT_START: {
                struct lustre_kernelcomm *lk = karg;
                if (lk->lk_flags & LK_FLG_STOP)
-                       rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
+                       rc = lmv_hsm_ct_unregister(obddev, cmd, len, lk, uarg);
                else
-                       rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
+                       rc = lmv_hsm_ct_register(obddev, cmd, len, lk, uarg);
                break;
        }
        default:
@@ -2556,6 +2554,7 @@ try_next_stripe:
 static int lmv_precleanup(struct obd_device *obd)
 {
        ENTRY;
+       libcfs_kkuc_group_rem(&obd->obd_uuid, 0, KUC_GRP_HSM);
        fld_client_proc_fini(&obd->u.lmv.lmv_fld);
        lprocfs_obd_cleanup(obd);
        lprocfs_free_md_stats(obd);
index b02866e..d6c2e7b 100644 (file)
@@ -2141,7 +2141,8 @@ static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
  * @param val KUC message (kuc_hdr + hsm_action_list)
  * @param len total length of message
  */
-static int mdc_hsm_copytool_send(size_t len, void *val)
+static int mdc_hsm_copytool_send(const struct obd_uuid *uuid,
+                                size_t len, void *val)
 {
        struct kuc_hdr          *lh = (struct kuc_hdr *)val;
        struct hsm_action_list  *hal = (struct hsm_action_list *)(lh + 1);
@@ -2167,7 +2168,7 @@ static int mdc_hsm_copytool_send(size_t len, void *val)
               lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
 
        /* Broadcast to HSM listeners */
-       rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
+       rc = libcfs_kkuc_group_put(uuid, KUC_GRP_HSM, lh);
 
        RETURN(rc);
 }
@@ -2187,9 +2188,6 @@ static int mdc_hsm_ct_reregister(void *data, void *cb_arg)
        if (kcd == NULL || kcd->kcd_magic != KKUC_CT_DATA_MAGIC)
                return -EPROTO;
 
-       if (!obd_uuid_equals(&kcd->kcd_uuid, &imp->imp_obd->obd_uuid))
-               return 0;
-
        CDEBUG(D_HA, "%s: recover copytool registration to MDT (archive=%#x)\n",
               imp->imp_obd->obd_name, kcd->kcd_archive);
        rc = mdc_ioc_hsm_ct_register(imp, kcd->kcd_archive);
@@ -2205,8 +2203,8 @@ static int mdc_hsm_ct_reregister(void *data, void *cb_arg)
 static int mdc_kuc_reregister(struct obd_import *imp)
 {
        /* re-register HSM agents */
-       return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
-                                        (void *)imp);
+       return libcfs_kkuc_group_foreach(&imp->imp_obd->obd_uuid, KUC_GRP_HSM,
+                                        mdc_hsm_ct_reregister, imp);
 }
 
 static int mdc_set_info_async(const struct lu_env *env,
@@ -2253,7 +2251,8 @@ static int mdc_set_info_async(const struct lu_env *env,
                 RETURN(rc);
         }
         if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
-                rc = mdc_hsm_copytool_send(vallen, val);
+               rc = mdc_hsm_copytool_send(&imp->imp_obd->obd_uuid, vallen,
+                                          val);
                 RETURN(rc);
         }
 
@@ -2555,10 +2554,6 @@ static int mdc_precleanup(struct obd_device *obd)
 {
        ENTRY;
 
-       /* Failsafe, ok if racy */
-       if (obd->obd_type->typ_refcnt <= 1)
-               libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
-
        mdc_changelog_cdev_finish(obd);
 
        obd_cleanup_client_import(obd);
index 9e4b84c..041d33e 100644 (file)
@@ -100,6 +100,7 @@ EXPORT_SYMBOL(libcfs_kkuc_msg_put);
 /** A single group registration has a uid and a file pointer */
 struct kkuc_reg {
        struct list_head kr_chain;
+       struct obd_uuid  kr_uuid;
        int              kr_uid;
        struct file     *kr_fp;
        char             kr_data[0];
@@ -128,8 +129,8 @@ void libcfs_kkuc_init(void)
  * @param group group number
  * @param data user data
  */
-int libcfs_kkuc_group_add(struct file *filp, int uid, int group,
-                         void *data, size_t data_len)
+int libcfs_kkuc_group_add(struct file *filp, const struct obd_uuid *uuid,
+                         int uid, int group, void *data, size_t data_len)
 {
        struct kkuc_reg *reg;
 
@@ -143,10 +144,11 @@ int libcfs_kkuc_group_add(struct file *filp, int uid, int group,
                return -EBADF;
 
        /* freed in group_rem */
-       reg = kmalloc(sizeof(*reg) + data_len, 0);
+       reg = kzalloc(sizeof(*reg) + data_len, 0);
        if (reg == NULL)
                return -ENOMEM;
 
+       reg->kr_uuid = *uuid;
        reg->kr_fp = filp;
        reg->kr_uid = uid;
        memcpy(reg->kr_data, data, data_len);
@@ -161,7 +163,7 @@ int libcfs_kkuc_group_add(struct file *filp, int uid, int group,
 }
 EXPORT_SYMBOL(libcfs_kkuc_group_add);
 
-int libcfs_kkuc_group_rem(int uid, int group)
+int libcfs_kkuc_group_rem(const struct obd_uuid *uuid, int uid, int group)
 {
        struct kkuc_reg *reg, *next;
        ENTRY;
@@ -179,12 +181,13 @@ int libcfs_kkuc_group_rem(int uid, int group)
                lh.kuc_transport = KUC_TRANSPORT_GENERIC;
                lh.kuc_msgtype = KUC_MSG_SHUTDOWN;
                lh.kuc_msglen = sizeof(lh);
-               libcfs_kkuc_group_put(group, &lh);
+               libcfs_kkuc_group_put(uuid, group, &lh);
        }
 
        down_write(&kg_sem);
        list_for_each_entry_safe(reg, next, &kkuc_groups[group], kr_chain) {
-               if ((uid == 0) || (uid == reg->kr_uid)) {
+               if (obd_uuid_equals(uuid, &reg->kr_uuid) &&
+                   (uid == 0 || uid == reg->kr_uid)) {
                        list_del(&reg->kr_chain);
                        CDEBUG(D_KUC, "Removed uid=%d fp=%p from group %d\n",
                                reg->kr_uid, reg->kr_fp, group);
@@ -199,7 +202,7 @@ int libcfs_kkuc_group_rem(int uid, int group)
 }
 EXPORT_SYMBOL(libcfs_kkuc_group_rem);
 
-int libcfs_kkuc_group_put(int group, void *payload)
+int libcfs_kkuc_group_put(const struct obd_uuid *uuid, int group, void *payload)
 {
        struct kkuc_reg *reg;
        int              rc = 0;
@@ -221,7 +224,8 @@ int libcfs_kkuc_group_put(int group, void *payload)
        }
 
        list_for_each_entry(reg, &kkuc_groups[group], kr_chain) {
-               if (reg->kr_fp != NULL) {
+               if (obd_uuid_equals(uuid, &reg->kr_uuid) &&
+                   reg->kr_fp != NULL) {
                        rc = libcfs_kkuc_msg_put(reg->kr_fp, payload);
                        if (rc == 0)
                                one_success = 1;
@@ -248,8 +252,8 @@ EXPORT_SYMBOL(libcfs_kkuc_group_put);
  * @param cb_func the function to be called.
  * @param cb_arg extra argument to be passed to the callback function.
  */
-int libcfs_kkuc_group_foreach(int group, libcfs_kkuc_cb_t cb_func,
-                             void *cb_arg)
+int libcfs_kkuc_group_foreach(const struct obd_uuid *uuid, int group,
+                             libcfs_kkuc_cb_t cb_func, void *cb_arg)
 {
        struct kkuc_reg *reg;
        int              rc = 0;
@@ -262,7 +266,7 @@ int libcfs_kkuc_group_foreach(int group, libcfs_kkuc_cb_t cb_func,
 
        down_read(&kg_sem);
        list_for_each_entry(reg, &kkuc_groups[group], kr_chain) {
-               if (reg->kr_fp != NULL)
+               if (obd_uuid_equals(uuid, &reg->kr_uuid) && reg->kr_fp != NULL)
                        rc = cb_func(reg->kr_data, cb_arg);
        }
        up_read(&kg_sem);