]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: clean up platform_nproc
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 1 Nov 2019 20:38:35 +0000 (16:38 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 1 Nov 2019 20:38:35 +0000 (16:38 -0400)
The platform_nproc function should check for error returns and obviously
garbage values and deal with them appropriately.  Fix the header
declaration since it's part of the libfrog platform support code, not
libxfs.  xfs_scrub will make use of it in the next patch.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/libxfs.h
include/platform_defs.h.in
libfrog/linux.c

index 63696df586451f63e9403b0fed3cf55bc1fd7b67..227084ae142e04e605b13d3970fcb17a0d250159 100644 (file)
@@ -135,7 +135,6 @@ extern void libxfs_device_close (dev_t);
 extern int     libxfs_device_alignment (void);
 extern void    libxfs_report(FILE *);
 extern void    platform_findsizes(char *path, int fd, long long *sz, int *bsz);
-extern int     platform_nproc(void);
 
 /* check or write log footer: specify device, log size in blocks & uuid */
 typedef char   *(libxfs_get_block_t)(char *, int, void *);
index d111ec6d2d37a84ee7dde48ac25869110379b8f5..adb0018132b2fcb061e12e03cec74eeaadc88118 100644 (file)
@@ -77,4 +77,6 @@ typedef unsigned short umode_t;
 # define ASSERT(EX)    ((void) 0)
 #endif
 
+extern int     platform_nproc(void);
+
 #endif /* __XFS_PLATFORM_DEFS_H__ */
index b6c24879da4985bea4eb70e448931e63f7a49314..79bd79eb9d16a891523a3d4e4ee5e3f8338196e3 100644 (file)
@@ -242,10 +242,17 @@ platform_align_blockdev(void)
        return max_block_alignment;
 }
 
+/* How many CPUs are online? */
 int
 platform_nproc(void)
 {
-       return sysconf(_SC_NPROCESSORS_ONLN);
+       long nproc = sysconf(_SC_NPROCESSORS_ONLN);
+
+       if (nproc < 1)
+               return 1;
+       if (nproc >= INT_MAX)
+               return INT_MAX;
+       return nproc;
 }
 
 unsigned long