From c73736545fafac4373569187e064aab9cd435320 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 6 Dec 2017 20:21:48 -0600 Subject: [PATCH] LU-10341 hsm: filter kkuc write by client UUID 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. Signed-off-by: John L. Hammond Change-Id: Ibbda253979739a1d56d3e132a51a482a02a0ec27 Reviewed-on: https://review.whamcloud.com/30419 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Faccini Bruno Reviewed-by: Oleg Drokin --- lustre/include/lustre_export.h | 1 - lustre/include/lustre_kernelcomm.h | 12 +++++------ lustre/include/obd.h | 1 - lustre/lmv/lmv_obd.c | 43 +++++++++++++++++++------------------- lustre/mdc/mdc_request.c | 20 +++++++----------- lustre/obdclass/kernelcomm.c | 26 +++++++++++++---------- 6 files changed, 49 insertions(+), 54 deletions(-) diff --git a/lustre/include/lustre_export.h b/lustre/include/lustre_export.h index ed511c8..b6f0234 100644 --- a/lustre/include/lustre_export.h +++ b/lustre/include/lustre_export.h @@ -445,7 +445,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; }; diff --git a/lustre/include/lustre_kernelcomm.h b/lustre/include/lustre_kernelcomm.h index db681c4..956edb7 100644 --- a/lustre/include/lustre_kernelcomm.h +++ b/lustre/include/lustre_kernelcomm.h @@ -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__ */ diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 8541a7e..e73ccb9 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -423,7 +423,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; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 69da555..a5024d7 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -210,7 +210,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) { @@ -291,8 +290,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; @@ -306,18 +303,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); @@ -530,7 +526,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]; @@ -788,10 +784,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; @@ -811,22 +808,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; @@ -835,8 +833,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); @@ -884,7 +882,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); @@ -1118,9 +1116,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: @@ -2623,6 +2621,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); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 070286b..5fef216 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -2158,7 +2158,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); @@ -2184,7 +2185,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); } @@ -2204,9 +2205,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); @@ -2222,8 +2220,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, @@ -2262,7 +2260,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); } @@ -2590,11 +2589,6 @@ static int mdc_precleanup(struct obd_device *obd) ENTRY; osc_precleanup_common(obd); - - /* 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); diff --git a/lustre/obdclass/kernelcomm.c b/lustre/obdclass/kernelcomm.c index ccd982c..c4948ba 100644 --- a/lustre/obdclass/kernelcomm.c +++ b/lustre/obdclass/kernelcomm.c @@ -99,6 +99,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]; @@ -127,8 +128,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; @@ -142,10 +143,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); @@ -160,7 +162,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; @@ -178,12 +180,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, ®->kr_uuid) && + (uid == 0 || uid == reg->kr_uid)) { list_del(®->kr_chain); CDEBUG(D_HSM, "Removed uid=%d fp=%p from group %d\n", reg->kr_uid, reg->kr_fp, group); @@ -198,7 +201,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; @@ -220,7 +223,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, ®->kr_uuid) && + reg->kr_fp != NULL) { rc = libcfs_kkuc_msg_put(reg->kr_fp, payload); if (rc == 0) one_success = 1; @@ -247,8 +251,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; @@ -261,7 +265,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, ®->kr_uuid) && reg->kr_fp != NULL) rc = cb_func(reg->kr_data, cb_arg); } up_read(&kg_sem); -- 1.8.3.1