[PATCH v2 22/29] xfsprogs: Stop using platform_nproc()

Pavel Reichl
2021-08-06T21:23:59Z

---
include/platform_defs.h.in | 1 +
libfrog/linux.c | 8 +++++++-
repair/phase4.c | 6 +++---
repair/prefetch.c | 2 +-
repair/slab.c | 2 +-
repair/xfs_repair.c | 2 +-
scrub/disk.c | 8 ++++----
7 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/include/platform_defs.h.in b/include/platform_defs.h.in
index 539bdbec..03bc255a 100644
--- a/include/platform_defs.h.in
+++ b/include/platform_defs.h.in
@@ -79,6 +79,7 @@ typedef unsigned short umode_t;
#endif

extern int platform_nproc(void);
+extern int nproc(void);

#define NSEC_PER_SEC (1000000000ULL)
#define NSEC_PER_USEC (1000ULL)
diff --git a/libfrog/linux.c b/libfrog/linux.c
index 891373c6..ee163661 100644
--- a/libfrog/linux.c
+++ b/libfrog/linux.c
@@ -285,7 +285,7 @@ platform_align_blockdev(void)

/* How many CPUs are online? */
int
-platform_nproc(void)
+nproc(void)
{
long nproc = sysconf(_SC_NPROCESSORS_ONLN);

@@ -296,6 +296,12 @@ platform_nproc(void)
return nproc;
}

+int
+platform_nproc(void)
+{
+ return nproc();
+}
+
unsigned long
platform_physmem(void)
{
diff --git a/repair/phase4.c b/repair/phase4.c
index 191b4842..c496deda 100644
--- a/repair/phase4.c
+++ b/repair/phase4.c
@@ -235,7 +235,7 @@ process_rmap_data(
if (!rmap_needs_work(mp))
return;

- create_work_queue(&wq, mp, platform_nproc());
+ create_work_queue(&wq, mp, nproc());
for (i = 0; i < mp->m_sb.sb_agcount; i++)
queue_work(&wq, check_rmap_btrees, i, NULL);
destroy_work_queue(&wq);
@@ -243,12 +243,12 @@ process_rmap_data(
if (!xfs_sb_version_hasreflink(&mp->m_sb))
return;

- create_work_queue(&wq, mp, platform_nproc());
+ create_work_queue(&wq, mp, nproc());
for (i = 0; i < mp->m_sb.sb_agcount; i++)
queue_work(&wq, compute_ag_refcounts, i, NULL);
destroy_work_queue(&wq);

- create_work_queue(&wq, mp, platform_nproc());
+ create_work_queue(&wq, mp, nproc());
for (i = 0; i < mp->m_sb.sb_agcount; i++) {
queue_work(&wq, process_inode_reflink_flags, i, NULL);
queue_work(&wq, check_refcount_btrees, i, NULL);
diff --git a/repair/prefetch.c b/repair/prefetch.c
index 48affa18..f01e1296 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -1024,7 +1024,7 @@ do_inode_prefetch(
*/
if (check_cache && !libxfs_bcache_overflowed()) {
queue.wq_ctx = mp;
- create_work_queue(&queue, mp, platform_nproc());
+ create_work_queue(&queue, mp, nproc());
for (i = 0; i < mp->m_sb.sb_agcount; i++)
queue_work(&queue, func, i, NULL);
destroy_work_queue(&queue);
diff --git a/repair/slab.c b/repair/slab.c
index 165f97ef..d9a94a81 100644
--- a/repair/slab.c
+++ b/repair/slab.c
@@ -234,7 +234,7 @@ qsort_slab(
return;
}

- create_work_queue(&wq, NULL, platform_nproc());
+ create_work_queue(&wq, NULL, nproc());
hdr = slab->s_first;
while (hdr) {
qs = malloc(sizeof(struct qsort_slab));
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index a5410919..fbbc8c6f 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -1030,7 +1030,7 @@ main(int argc, char **argv)
}

if (ag_stride) {
- int max_threads = platform_nproc() * 8;
+ int max_threads = nproc() * 8;

thread_count = (glob_agcount + ag_stride - 1) / ag_stride;
while (thread_count > max_threads) {
diff --git a/scrub/disk.c b/scrub/disk.c
index a1ef798a..9b91eedd 100644
--- a/scrub/disk.c
+++ b/scrub/disk.c
@@ -43,19 +43,19 @@ __disk_heads(
{
int iomin;
int ioopt;
- int nproc = platform_nproc();
+ int n_proc = nproc();
unsigned short rot;
int error;

/* If it's not a block device, throw all the CPUs at it. */
if (!S_ISBLK(disk->d_sb.st_mode))
- return nproc;
+ return n_proc;

/* Non-rotational device? Throw all the CPUs at the problem. */
rot = 1;
error = ioctl(disk->d_fd, BLKROTATIONAL, &rot);
if (error == 0 && rot == 0)
- return nproc;
+ return n_proc;

/*
* Sometimes we can infer the number of devices from the
@@ -65,7 +65,7 @@ __disk_heads(
if (ioctl(disk->d_fd, BLKIOMIN, &iomin) == 0 &&
ioctl(disk->d_fd, BLKIOOPT, &ioopt) == 0 &&
iomin > 0 && ioopt > 0) {
- return min(nproc, max(1, ioopt / iomin));
+ return min(n_proc, max(1, ioopt / iomin));
}

/* Rotating device? I guess? */
--
2.31.1