Whamcloud - gitweb
LU-14093 mgc: rework mgc_apply_recover_logs() for gcc10 84/40484/8
authorAlex Zhuravlev <bzzz@whamcloud.com>
Tue, 3 Aug 2021 14:15:10 +0000 (10:15 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 18 Aug 2021 01:57:56 +0000 (01:57 +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);

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ice863b412475e53705dc6523ab30ba613244bd90
Reviewed-on: https://review.whamcloud.com/40484
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mgc/mgc_request.c

index 65ecd67..96973e1 100644 (file)
@@ -1374,7 +1374,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        struct lustre_cfg *lcfg;
        struct lustre_cfg_bufs bufs;
        u64 prev_version = 0;
        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;
        char *buf;
        int bufsz;
        int pos = 0;
@@ -1389,32 +1389,25 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        /* get dynamic nids setting */
        dynamic_nids = mgc->obd_dynamic_nids;
 
        /* get dynamic nids setting */
        dynamic_nids = mgc->obd_dynamic_nids;
 
-       OBD_ALLOC(inst, PAGE_SIZE);
-       if (inst == NULL)
-               RETURN(-ENOMEM);
-
        if (!IS_SERVER(lsi)) {
        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;
                        return -E2BIG;
-               }
 #ifdef HAVE_SERVER_SUPPORT
        } else {
                LASSERT(IS_MDT(lsi));
                rc = server_name2svname(lsi->lsi_svname, inst, NULL,
 #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);
                        RETURN(-EINVAL);
-               }
-               pos = strlen(inst);
 #endif /* HAVE_SERVER_SUPPORT */
        }
 
 #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);
 
        while (datalen > 0) {
                int   entry_len = sizeof(*entry);
@@ -1498,7 +1491,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                               is_ost ? "OST" : "MDT", entry->mne_index);
 
                cname = is_ost ? "osc" : "mdc",
                               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 */
                lustre_cfg_bufs_reset(&bufs, obdname);
 
                /* find the obd by obdname */
@@ -1601,8 +1594,9 @@ fail:;
                /* continue, even one with error */
        }
 
                /* continue, even one with error */
        }
 
-       OBD_FREE(inst, PAGE_SIZE);
-        RETURN(rc);
+       OBD_FREE(buf, PAGE_SIZE);
+
+       RETURN(rc);
 }
 
 /**
 }
 
 /**