diff --git a/lustre/include/lustre_disk.h b/lustre/include/lustre_disk.h index 204c183512eeae4cb892ffed8a685b5216b3cfb5..805cf40fba2c5aa4681612a184e9ae458407f16b 100644 --- a/lustre/include/lustre_disk.h +++ b/lustre/include/lustre_disk.h @@ -281,7 +281,7 @@ struct mgs_target_info; int server_mti_print(char *title, struct mgs_target_info *mti); /* mgc_request.c */ -int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id); +int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id); #endif diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index ee88068a5fb29c6f80d856669c5a2d1d406267cf..8a671a1e773cab9096b1c352a3c63498033d39ce 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -45,38 +45,50 @@ #include <lustre_fsfilt.h> #include <lustre_disk.h> - -int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id) +static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id) { - char *name_end; - int len; __u64 resname = 0; - - /* fsname is at most 8 chars long at the beginning of the logname - e.g. "lustre-MDT0001" or "lustre" */ - name_end = strrchr(logname, '-'); - if (name_end) - len = name_end - logname; - else - len = strlen(logname); + if (len > 8) { - CERROR("fsname too long: %s\n", logname); + CERROR("name too long: %s\n", name); return -EINVAL; } if (len <= 0) { - CERROR("missing fsname: %s\n", logname); + CERROR("missing name: %s\n", name); return -EINVAL; } - memcpy(&resname, logname, len); + memcpy(&resname, name, len); memset(res_id, 0, sizeof(*res_id)); + /* Always use the same endianness for the resid */ res_id->name[0] = cpu_to_le64(resname); - CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", logname, + CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", name, res_id->name[0], res_id->name[1], (char *)&res_id->name[0]); return 0; } -EXPORT_SYMBOL(mgc_logname2resid); + +int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id) +{ + /* fsname is at most 8 chars long, maybe contain "-". + * e.g. "lustre", "CFS-000" */ + return mgc_name2resid(fsname, strlen(fsname), res_id); +} +EXPORT_SYMBOL(mgc_fsname2resid); + +int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id) +{ + char *name_end; + int len; + + /* logname consists of "fsname-nodetype". + * e.g. "lustre-MDT0001", "CFS-000-client" */ + name_end = strrchr(logname, '-'); + LASSERT(name_end); + len = name_end - logname; + return mgc_name2resid(logname, len, res_id); +} + /********************** config llog list **********************/ static struct list_head config_llog_list = LIST_HEAD_INIT(config_llog_list); diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 95227e407e47941a9097e90b6a73e0183ee9085a..f47a65875174cabe302e202beb5921ed92b6911e 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -288,7 +288,7 @@ static int mgs_get_cfg_lock(struct obd_device *obd, char *fsname, int rc, flags = 0; ENTRY; - rc = mgc_logname2resid(fsname, &res_id); + rc = mgc_fsname2resid(fsname, &res_id); if (!rc) rc = ldlm_cli_enqueue_local(obd->obd_namespace, res_id, LDLM_PLAIN, NULL, LCK_EX,