Whamcloud - gitweb
LU-12898 utils: %llu mismatch with type __u64 on ppcle64 58/36558/7
authorOlaf Faaland <faaland1@llnl.gov>
Tue, 22 Oct 2019 16:44:51 +0000 (09:44 -0700)
committerOleg Drokin <green@whamcloud.com>
Fri, 3 Jan 2020 00:09:12 +0000 (00:09 +0000)
Fix build errors like this one on ppcle64:

BUILDSTDERR: libmount_utils_zfs.c: In function 'zfs_mkfs_opts':
BUILDSTDERR: libmount_utils_zfs.c:573:5: error: format '%llu' expects
argument of type 'long long unsigned int', but argument 4 has type
'__u64' [-Werror=format=]
BUILDSTDERR:      mop->mo_device_kb * 1024);

__u64 was treated as an unsigned long long which breaks the build on
ppc64le, where they are not the same size.

In printf cases, cast to unsigned long long to match the printf format
so the format is compatible with the type and it is guaranteed
not to lose any data.

In the case of sscanf(), replace the call with strtoull() to eliminate
the issue.

Test-Parameters: trivial
Change-Id: I02fd82e0be4d756881c15aa9faedb9b40961661a
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Reviewed-on: https://review.whamcloud.com/36558
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
lustre/utils/libmount_utils_zfs.c
lustre/utils/ll_decode_filter_fid.c
lustre/utils/llog_reader.c
lustre/utils/lr_reader.c
lustre/utils/lsnapshot.c
lustre/utils/lustre_lfsck.c

index a4fe85e..9e468ad 100644 (file)
@@ -642,7 +642,7 @@ static char *zfs_mkfs_opts(struct mkfs_opts *mop, char *str, int len)
                snprintf(str, len, " -o %s", mop->mo_mkfsopts);
        if (mop->mo_device_kb)
                snprintf(str, len, " -o quota=%llu",
-                        mop->mo_device_kb * 1024);
+                        (unsigned long long)mop->mo_device_kb * 1024);
 
        return str;
 }
index eb86e1c..c1c2b38 100644 (file)
@@ -134,8 +134,8 @@ int main(int argc, char *argv[])
                                               "component_start=%llu "
                                               "component_end=%llu",
                                               loa->loa_comp_id,
-                                              loa->loa_comp_start,
-                                              loa->loa_comp_end);
+                                              (unsigned long long)loa->loa_comp_start,
+                                              (unsigned long long)loa->loa_comp_end);
                                printf("\n");
                                continue;
                        }
@@ -187,7 +187,9 @@ int main(int argc, char *argv[])
                                       "component_start=%llu "
                                       "component_end=%llu",
                                       __le32_to_cpu(ol->ol_comp_id),
+                                      (unsigned long long)
                                       __le64_to_cpu(ol->ol_comp_start),
+                                      (unsigned long long)
                                       __le64_to_cpu(ol->ol_comp_end));
                }
                if (size >= sizeof(struct filter_fid))
index 01e59de..c0b6e15 100644 (file)
@@ -642,25 +642,25 @@ static void print_hsm_action(struct llog_agent_req_rec *larr)
 
        sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
        printf("lrh=[type=%X len=%d idx=%d] fid="DFID
-              " compound/cookie=%#jx/%#jx"
-              " status=%s action=%s archive#=%d flags=%#jx"
-              " create=%ju change=%ju"
-              " extent=%#jx-%#jx gid=%#jx datalen=%d"
+              " compound/cookie=%#llx/%#llx"
+              " status=%s action=%s archive#=%d flags=%#llx"
+              " create=%llu change=%llu"
+              " extent=%#llx-%#llx gid=%#llx datalen=%d"
               " data=[%s]\n",
               larr->arr_hdr.lrh_type,
               larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
               PFID(&larr->arr_hai.hai_fid),
-              (uintmax_t)larr->arr_compound_id,
-              (uintmax_t)larr->arr_hai.hai_cookie,
+              (unsigned long long)larr->arr_compound_id,
+              (unsigned long long)larr->arr_hai.hai_cookie,
               agent_req_status2name(larr->arr_status),
               hsm_copytool_action2name(larr->arr_hai.hai_action),
               larr->arr_archive_id,
-              (uintmax_t)larr->arr_flags,
-              (uintmax_t)larr->arr_req_create,
-              (uintmax_t)larr->arr_req_change,
-              (uintmax_t)larr->arr_hai.hai_extent.offset,
-              (uintmax_t)larr->arr_hai.hai_extent.length,
-              (uintmax_t)larr->arr_hai.hai_gid, sz,
+              (unsigned long long)larr->arr_flags,
+              (unsigned long long)larr->arr_req_create,
+              (unsigned long long)larr->arr_req_change,
+              (unsigned long long)larr->arr_hai.hai_extent.offset,
+              (unsigned long long)larr->arr_hai.hai_extent.length,
+              (unsigned long long)larr->arr_hai.hai_gid, sz,
               hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
 }
 
@@ -674,7 +674,7 @@ void print_changelog_rec(struct llog_changelog_rec *rec)
        printf("changelog record id:0x%x index:%llu cr_flags:0x%x "
               "cr_type:%s(0x%x) date:'%02d:%02d:%02d.%09d %04d.%02d.%02d' "
               "target:"DFID, __le32_to_cpu(rec->cr_hdr.lrh_id),
-              __le64_to_cpu(rec->cr.cr_index),
+              (unsigned long long)__le64_to_cpu(rec->cr.cr_index),
               __le32_to_cpu(rec->cr.cr_flags),
               changelog_type2str(__le32_to_cpu(rec->cr.cr_type)),
               __le32_to_cpu(rec->cr.cr_type),
@@ -696,7 +696,7 @@ void print_changelog_rec(struct llog_changelog_rec *rec)
                        changelog_rec_extra_flags(&rec->cr);
 
                printf(" cr_extra_flags:0x%llx",
-                      __le64_to_cpu(ef->cr_extra_flags));
+                      (unsigned long long)__le64_to_cpu(ef->cr_extra_flags));
 
                if (ef->cr_extra_flags & CLFE_UIDGID) {
                        struct changelog_ext_uidgid *uidgid =
index 21be0d6..f1072a2 100644 (file)
@@ -209,9 +209,11 @@ int main(int argc, char *const argv[])
        printf("  feature_compat: %#x\n", lsd.lsd_feature_compat);
        printf("  feature_incompat: %#x\n", lsd.lsd_feature_incompat);
        printf("  feature_rocompat: %#x\n", lsd.lsd_feature_rocompat);
-       printf("  last_transaction: %llu\n", lsd.lsd_last_transno);
+       printf("  last_transaction: %llu\n",
+              (unsigned long long)lsd.lsd_last_transno);
        printf("  target_index: %u\n", lsd.lsd_osd_index);
-       printf("  mount_count: %llu\n", lsd.lsd_mount_count);
+       printf("  mount_count: %llu\n",
+              (unsigned long long)lsd.lsd_mount_count);
 
        /* read client information */
        if (opt_client) {
@@ -259,8 +261,9 @@ int main(int argc, char *const argv[])
                        printf("\n  %.40s:\n", lcd.lcd_uuid);
                        printf("    generation: %u\n", lcd.lcd_generation);
                        printf("    last_transaction: %llu\n",
-                              lcd.lcd_last_transno);
-                       printf("    last_xid: %llu\n", lcd.lcd_last_xid);
+                              (unsigned long long)lcd.lcd_last_transno);
+                       printf("    last_xid: %llu\n",
+                              (unsigned long long)lcd.lcd_last_xid);
                        printf("    last_result: %u\n", lcd.lcd_last_result);
                        printf("    last_data: %u\n", lcd.lcd_last_data);
 
@@ -275,9 +278,9 @@ int main(int argc, char *const argv[])
                                lcd.lcd_last_close_data =
                                        __le32_to_cpu(lcd.lcd_last_close_data);
                                printf("    last_close_transation: %llu\n",
-                                      lcd.lcd_last_close_transno);
+                                      (unsigned long long)lcd.lcd_last_close_transno);
                                printf("    last_close_xid: %llu\n",
-                                      lcd.lcd_last_close_xid);
+                                      (unsigned long long)lcd.lcd_last_close_xid);
                                printf("    last_close_result: %u\n",
                                       lcd.lcd_last_close_result);
                                printf("    last_close_data: %u\n",
@@ -375,10 +378,13 @@ int main(int argc, char *const argv[])
                        printf("  %lld:\n", slot);
                        printf("    client_generation: %u\n",
                               lrd.lrd_client_gen);
-                       printf("    last_transaction: %llu\n", lrd.lrd_transno);
-                       printf("    last_xid: %llu\n", lrd.lrd_xid);
+                       printf("    last_transaction: %lluu\n",
+                              (unsigned long long)lrd.lrd_transno);
+                       printf("    last_xid: %llu\n",
+                              (unsigned long long)lrd.lrd_xid);
                        printf("    last_result: %u\n", lrd.lrd_result);
-                       printf("    last_data: %llu\n\n", lrd.lrd_data);
+                       printf("    last_data: %llu\n\n",
+                              (unsigned long long)lrd.lrd_data);
                }
        }
 
index 8ad6acc..0f1539e 100644 (file)
@@ -1237,7 +1237,9 @@ static int __snapshot_create(struct snapshot_instance *si,
                                        "-o lustre:ctime=%llu "
                                        "-o lustre:mtime=%llu ",
                                        PRSH(si, st), PZFS(st), fsname,
-                                       SNAPSHOT_MAGIC, xtime, xtime);
+                                       SNAPSHOT_MAGIC,
+                                       (unsigned long long)xtime,
+                                       (unsigned long long)xtime);
                        if (len <= 0)
                                exit(-EOVERFLOW);
 
@@ -1801,7 +1803,8 @@ static int __snapshot_modify(struct snapshot_instance *si,
                                         PRSH(si, st), PIMPORT(st), PZFS(st),
                                         PSSNAME(si, st), PSS_NEW(si, st),
                                         PZFS(st), si->si_comment,
-                                        PSS_NEW(si, st), PZFS(st), xtime,
+                                        PSS_NEW(si, st), PZFS(st),
+                                        (unsigned long long)xtime,
                                         PSS_NEW(si, st));
                        else if (si->si_new_ssname)
                                snprintf(cmd, sizeof(cmd) - 1,
@@ -1810,7 +1813,8 @@ static int __snapshot_modify(struct snapshot_instance *si,
                                         " set lustre:mtime=%llu "DSSNAME"'",
                                         PRSH(si, st), PIMPORT(st), PZFS(st),
                                         PSSNAME(si, st), PSS_NEW(si, st),
-                                        PZFS(st), xtime, PSS_NEW(si, st));
+                                        PZFS(st), (unsigned long long)xtime,
+                                        PSS_NEW(si, st));
                        else if (si->si_comment)
                                snprintf(cmd, sizeof(cmd) - 1,
                                         DRSH" '"DIMPORT"; "DZFS
@@ -1819,7 +1823,8 @@ static int __snapshot_modify(struct snapshot_instance *si,
                                         " set lustre:mtime=%llu "DSSNAME"'",
                                         PRSH(si, st), PIMPORT(st), PZFS(st),
                                         si->si_comment, PSSNAME(si, st),
-                                        PZFS(st), xtime, PSSNAME(si, st));
+                                        PZFS(st), (unsigned long long)xtime,
+                                        PSSNAME(si, st));
                        else
                                exit(-EINVAL);
 
@@ -1978,7 +1983,7 @@ static int snapshot_list_one(struct snapshot_instance *si,
                            strlen("lustre:ctime")) == 0) {
                        ptr = snapshot_first_skip_blank(buf);
                        if (ptr) {
-                               sscanf(ptr, "%llu", &xtime);
+                               xtime = (__u64)strtoull(ptr, NULL, 10);
                                printf("create_time: %s",
                                       ctime((time_t *)&xtime));
                        }
@@ -1989,7 +1994,7 @@ static int snapshot_list_one(struct snapshot_instance *si,
                            strlen("lustre:mtime")) == 0) {
                        ptr = snapshot_first_skip_blank(buf);
                        if (ptr) {
-                               sscanf(ptr, "%llu", &xtime);
+                               xtime = (__u64)strtoull(ptr, NULL, 10);
                                printf("modify_time: %s",
                                       ctime((time_t *)&xtime));
                        }
index b6bef2a..5e48932 100644 (file)
@@ -629,7 +629,8 @@ bad_type:
                        printf("%s_osts_%s: %d\n", name,
                               lfsck_status2name(j), query.lu_osts_count[i][j]);
 
-               printf("%s_repaired: %llu\n", name, query.lu_repaired[i]);
+               printf("%s_repaired: %llu\n", name,
+                      (unsigned long long)query.lu_repaired[i]);
        }
 
        return 0;