From: Andreas Dilger Date: Fri, 1 May 2020 08:02:22 +0000 (-0600) Subject: LU-13499 obd: fix printing of client connection UUID X-Git-Tag: 2.13.54~102 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=9abdf96e56e239b81102c8a43dc2f0524f2be90a;ds=sidebyside LU-13499 obd: fix printing of client connection UUID The client connection UUID sent to the servers (ASCII format) was being truncated to only 16 bytes in size, like '595f3c6a-20ae-4' instead of a full UUID like '18ae0f9a-4b09-4599-8ced-0f2126eab425'. This was caused by using UUID_SIZE to limit the size of the "%pU" string printed to avoid overflowing the target buffer, but in fact UUID_SIZE is the size of the binary uuid_t (16 bytes) instead of the size of struct obd_uuid (40 bytes) where the ASCII version of the UUID is stored. Fix this to use sizeof(target) rather than an external constant, which is exactly why sizeof(target) should always be used. The usage in osd_scrub.c is not actually broken, but it is still better to use sizeof(target) to avoid future inconsistencies. Fixes: 604c266a175b7 ("LU-11803 obd: replace class_uuid with linux kernel version") Signed-off-by: Andreas Dilger Change-Id: I05325646cd632a09997d6632a483909629ce7057 Reviewed-on: https://review.whamcloud.com/38443 Tested-by: jenkins Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index d2168de..41cf4aa 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -1104,7 +1104,7 @@ int ll_fill_super(struct super_block *sb) /* UUID handling */ generate_random_uuid(uuid.b); - snprintf(sbi->ll_sb_uuid.uuid, UUID_SIZE, "%pU", uuid.b); + snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b); CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 5edc929..6616d49 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -410,7 +410,7 @@ int lustre_start_mgc(struct super_block *sb) GOTO(out_free, rc = -ENOMEM); generate_random_uuid(uuidc.b); - snprintf(uuid->uuid, UUID_SIZE, "%pU", uuidc.b); + snprintf(uuid->uuid, sizeof(*uuid), "%pU", uuidc.b); /* Start the MGC */ rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME, diff --git a/lustre/osd-ldiskfs/osd_scrub.c b/lustre/osd-ldiskfs/osd_scrub.c index ed25083..7ad1f8d 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -2623,7 +2623,7 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev) RETURN(obj ? PTR_ERR(obj) : -ENOENT); #ifndef HAVE_S_UUID_AS_UUID_T - memcpy(dev->od_uuid.b, sb->s_uuid, UUID_SIZE); + memcpy(dev->od_uuid.b, sb->s_uuid, sizeof(dev->od_uuid)); #else uuid_copy(&dev->od_uuid, &sb->s_uuid); #endif