From a6e430e81669a6ab40ecae9b416dd2cdee45908c Mon Sep 17 00:00:00 2001 From: Hongchao Zhang Date: Sun, 9 Oct 2016 03:49:33 +0800 Subject: [PATCH] LU-7481 utils: label lustre device correctly Currently, the device label will be read before mounting Lustre, the flags LDD_F_VIRGIN and LDD_F_WRITECONF will be set according to the label (the corresponding original flags containing in the lustre_disk_data will be ignored). But the device label could be changed during mount by the journal recovery, and the device should be also labeled to indicate the target device is supposed to start. Test-Parameters: testlist=conf-sanity,conf-sanity,conf-sanity Change-Id: I2df1d81f764a7d1ffa26afb0197d137c057a25e9 Signed-off-by: Hongchao Zhang Reviewed-on: https://review.whamcloud.com/24845 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- lustre/utils/mount_lustre.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 75d17b2..1126748 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -684,6 +684,34 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop) return 0; } +/* change label from : to + * - to indicate the device has + * been registered. only if the label is + * supposed to be changed and target service + * is supposed to start */ +static void label_lustre(struct mount_opts *mop) +{ + if (mop->mo_nosvc) + return; + + if (mop->mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) { + (void)osd_label_lustre(mop); + } else { + struct lustre_disk_data ldd; + int rc; + + /* device label could be changed after journal recovery, + * it should also be relabeled for mount has succeeded. */ + memset(&ldd, 0, sizeof(ldd)); + rc = osd_read_ldd(mop->mo_source, &ldd); + if (rc == 0) { + rc = strlen(ldd.ldd_svname); + if (rc >= 8 && ldd.ldd_svname[rc - 8] != '-') + (void)osd_label_lustre(mop); + } + } +} + int main(int argc, char *const argv[]) { struct mount_opts mop; @@ -819,16 +847,7 @@ int main(int argc, char *const argv[]) rc = mount(mop.mo_source, mop.mo_target, "lustre", flags, (void *)options); if (rc == 0) { - /* change label from : to - * - to indicate the device has - * been registered. only if the label is - * supposed to be changed and target service - * is supposed to start */ - if (mop.mo_ldd.ldd_flags & - (LDD_F_VIRGIN | LDD_F_WRITECONF)) { - if (mop.mo_nosvc == 0) - (void)osd_label_lustre(&mop); - } + label_lustre(&mop); } else { if (verbose) { fprintf(stderr, "%s: mount %s at %s " -- 1.8.3.1