Whamcloud - gitweb
LU-14093 mgc: rework mgc_apply_recover_logs() for gcc10
authorAlex Zhuravlev <bzzz@whamcloud.com>
Thu, 20 Jan 2022 01:07:02 +0000 (17:07 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 21 Jan 2022 23:23:20 +0000 (23:23 +0000)
rework mgc_apply_recover_logs() to use a separate buffer of
appropriate size so that gcc10 doesn't complain:
mgc_request.c:1506:24: error: argument 4 may overlap destination
        object [-Werror=restrict]
 1506 |        pos += sprintf(obdname + pos, "-%s-%s", cname, inst);

Lustre-change: https://review.whamcloud.com/40484
Lustre-commit: d13d8158e816b7ac4437ff6d6c6aec3926ba7531

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ice863b412475e53705dc6523ab30ba613244bd90
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/46217
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/mgc/mgc_request.c

index 84142d9..e5f580e 100644 (file)
@@ -1373,7 +1373,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        struct lustre_cfg *lcfg;
        struct lustre_cfg_bufs bufs;
        u64 prev_version = 0;
-       char *inst;
+       char inst[MTI_NAME_MAXLEN + 1];
        char *buf;
        int bufsz;
        int pos = 0;
@@ -1388,32 +1388,25 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        /* get dynamic nids setting */
        dynamic_nids = mgc->obd_dynamic_nids;
 
-       OBD_ALLOC(inst, PAGE_SIZE);
-       if (inst == NULL)
-               RETURN(-ENOMEM);
-
        if (!IS_SERVER(lsi)) {
-               pos = snprintf(inst, PAGE_SIZE, "%016lx", cfg->cfg_instance);
-               if (pos >= PAGE_SIZE) {
-                       OBD_FREE(inst, PAGE_SIZE);
+               pos = snprintf(inst, sizeof(inst), "%016lx", cfg->cfg_instance);
+               if (pos >= PAGE_SIZE)
                        return -E2BIG;
-               }
 #ifdef HAVE_SERVER_SUPPORT
        } else {
                LASSERT(IS_MDT(lsi));
                rc = server_name2svname(lsi->lsi_svname, inst, NULL,
-                                       PAGE_SIZE);
-               if (rc) {
-                       OBD_FREE(inst, PAGE_SIZE);
+                                       sizeof(inst));
+               if (rc)
                        RETURN(-EINVAL);
-               }
-               pos = strlen(inst);
 #endif /* HAVE_SERVER_SUPPORT */
        }
 
-       ++pos;
-       buf   = inst + pos;
-       bufsz = PAGE_SIZE - pos;
+       OBD_ALLOC(buf, PAGE_SIZE);
+       if (!buf)
+               return -ENOMEM;
+       bufsz = PAGE_SIZE;
+       pos = 0;
 
        while (datalen > 0) {
                int   entry_len = sizeof(*entry);
@@ -1496,7 +1489,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                                   is_ost ? "OST" : "MDT", entry->mne_index);
 
                 cname = is_ost ? "osc" : "mdc",
-                pos += sprintf(obdname + pos, "-%s-%s", cname, inst);
+               pos += snprintf(obdname + pos, bufsz, "-%s-%s", cname, inst);
                 lustre_cfg_bufs_reset(&bufs, obdname);
 
                 /* find the obd by obdname */
@@ -1602,8 +1595,9 @@ fail:
                 /* continue, even one with error */
         }
 
-       OBD_FREE(inst, PAGE_SIZE);
-        RETURN(rc);
+       OBD_FREE(buf, PAGE_SIZE);
+
+       RETURN(rc);
 }
 
 /**