Skip to contentSkip to conversation

physmem: replace function name with __func__ in ram_block_discard_range()

PATCH Applied Xiaoyao Li 4 participants 4 messages Jan 25, 2024

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

PATCH 1/1 physmem: replace function name with __func__ in ram_block_discard_range()

Use __func__ to avoid hard-coded function name.

---
 system/physmem.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)
system/physmem.c +17 -21
index cc68a7976378..c1b22bac77c2 100644
@@ -3500,16 +3500,15 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
     uint8_t *host_startaddr = rb->host + start;
 
     if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) {
-        error_report("ram_block_discard_range: Unaligned start address: %p",
-                     host_startaddr);
+        error_report("%s: Unaligned start address: %p",
+                     __func__, host_startaddr);
         goto err;
     }
 
     if ((start + length) <= rb->max_length) {
         bool need_madvise, need_fallocate;
         if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
-            error_report("ram_block_discard_range: Unaligned length: %zx",
-                         length);
+            error_report("%s: Unaligned length: %zx", __func__, length);
             goto err;
         }
 
@@ -3533,8 +3532,8 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              * proper error message.
              */
             if (rb->flags & RAM_READONLY_FD) {
-                error_report("ram_block_discard_range: Discarding RAM"
-                             " with readonly files is not supported");
+                error_report("%s: Discarding RAM with readonly files is not"
+                             " supported", __func__);
                 goto err;
 
             }
@@ -3549,27 +3548,26 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              * file.
              */
             if (!qemu_ram_is_shared(rb)) {
-                warn_report_once("ram_block_discard_range: Discarding RAM"
+                warn_report_once("%s: Discarding RAM"
                                  " in private file mappings is possibly"
                                  " dangerous, because it will modify the"
                                  " underlying file and will affect other"
-                                 " users of the file");
+                                 " users of the file", __func__);
             }
 
             ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                             start, length);
             if (ret) {
                 ret = -errno;
-                error_report("ram_block_discard_range: Failed to fallocate "
-                             "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)",
+                             __func__, rb->idstr, start, length, ret);
                 goto err;
             }
 #else
             ret = -ENOSYS;
-            error_report("ram_block_discard_range: fallocate not available/file"
+            error_report("%s: fallocate not available/file"
                          "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+                         __func__, rb->idstr, start, length, ret);
             goto err;
 #endif
         }
@@ -3587,25 +3585,23 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
             }
             if (ret) {
                 ret = -errno;
-                error_report("ram_block_discard_range: Failed to discard range "
+                error_report("%s: Failed to discard range "
                              "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                             __func__, rb->idstr, start, length, ret);
                 goto err;
             }
 #else
             ret = -ENOSYS;
-            error_report("ram_block_discard_range: MADVISE not available"
-                         "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+            error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%d)",
+                         __func__, rb->idstr, start, length, ret);
             goto err;
 #endif
         }
         trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
                                       need_madvise, need_fallocate, ret);
     } else {
-        error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu64
-                     "/%zx/" RAM_ADDR_FMT")",
-                     rb->idstr, start, length, rb->max_length);
+        error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_FMT")",
+                     __func__, rb->idstr, start, length, rb->max_length);
     }
 
 err:
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 12 lines · Xiaoyao Li

Use __func__ to avoid hard-coded function name.

---
  system/physmem.c | 38 +++++++++++++++++---------------------
  1 file changed, 17 insertions(+), 21 deletions(-)
      if ((start + length) <= rb->max_length) {
          bool need_madvise, need_fallocate;
          if (!QEMU_IS_ALIGNED(length, rb->page_size)) {

system/physmem.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 3511

Quoted 3 lines
system/physmem.c +1 -2
-            error_report("ram_block_discard_range: Unaligned length: %zx",
-                         length);
+            error_report("%s: Unaligned length: %zx", __func__, length);

Pre-existing, should we enforce 0x prefix for %*x format?

See https://www.qemu.org/docs/master/devel/style.html#printf-flag
and related commit c3e5875afc ("checkpatch: check trace-events code style") for rationale.

$ git grep '[^x]%zx'
accel/tcg/perf.c:239:        fprintf(perfmap, "%"PRIxPTR" %zx tcg-prologue-buffer\n",
gdbstub/user-target.c:300:    g_string_printf(gdbserver_state.str_buf, "F%zx;", n);
migration/postcopy-ram.c:759:        error_report("%s: Failed to wake: %zx in %s (%s)",
migration/trace-events:100:ram_discard_range(const char *rbname, uint64_t start, size_t len) "%s: start: %" PRIx64 " %zx"
system/physmem.c:3511:            error_report("ram_block_discard_range: Unaligned length: %zx",
system/physmem.c:3564:                             "%s:%" PRIx64 " +%zx (%d)",
system/physmem.c:3571:                         "%s:%" PRIx64 " +%zx (%d)",
system/physmem.c:3591:                             "%s:%" PRIx64 " +%zx (%d)",
system/physmem.c:3598:                         "%s:%" PRIx64 " +%zx (%d)",
system/physmem.c:3607:                     "/%zx/" RAM_ADDR_FMT")",
Quoted 39 lines
              if (ret) {
                  ret = -errno;
system/physmem.c +8 -10
-                error_report("ram_block_discard_range: Failed to fallocate "
-                             "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)",
+                             __func__, rb->idstr, start, length, ret);
                  goto err;
              }
  #else
              ret = -ENOSYS;
-            error_report("ram_block_discard_range: fallocate not available/file"
+            error_report("%s: fallocate not available/file"
                           "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+                         __func__, rb->idstr, start, length, ret);
              goto err;
  #endif
          }
@@ -3587,25 +3585,23 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              }
              if (ret) {
                  ret = -errno;
-                error_report("ram_block_discard_range: Failed to discard range "
+                error_report("%s: Failed to discard range "
                               "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                             __func__, rb->idstr, start, length, ret);
                  goto err;
              }
  #else
              ret = -ENOSYS;
-            error_report("ram_block_discard_range: MADVISE not available"
-                         "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+            error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%d)",
+                         __func__, rb->idstr, start, length, ret);
              goto err;
  #endif

system/physmem.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 3605

Quoted 10 lines
system/physmem.c +2 -3
          }
          trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
                                        need_madvise, need_fallocate, ret);
      } else {
-        error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu64
-                     "/%zx/" RAM_ADDR_FMT")",
-                     rb->idstr, start, length, rb->max_length);
+        error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_FMT")",
+                     __func__, rb->idstr, start, length, rb->max_length);
      }
#2 lore raw
Quoted 12 lines · Philippe Mathieu-Daudé

Hi,

Quoted 7 lines · Xiaoyao Li

Use __func__ to avoid hard-coded function name.

---
   system/physmem.c | 38 +++++++++++++++++---------------------
   1 file changed, 17 insertions(+), 21 deletions(-)
Quoted 8 lines

system/physmem.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 3511

Quoted 6 lines
       if ((start + length) <= rb->max_length) {
           bool need_madvise, need_fallocate;
           if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
system/physmem.c +1 -2
-            error_report("ram_block_discard_range: Unaligned length: %zx",
-                         length);
+            error_report("%s: Unaligned length: %zx", __func__, length);

Pre-existing, should we enforce 0x prefix for %*x format?

Likely yes, but then, most of these errors here are more similar to assertions that we never ever see unless we have real bugs in QEMU. So I wouldn't lose sleep over it.

Signature · 3 lines
Cheers,

David / dhildenb