Message ID | 157177009113.1460186.17260250829884616599.stgit@magnolia (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | libfrog: take over platform code headers | expand |
On 10/22/19 1:48 PM, Darrick J. Wong wrote: > From: Darrick J. Wong <darrick.wong@oracle.com> > > 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>
diff --git a/include/libxfs.h b/include/libxfs.h index 63696df5..227084ae 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -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 *); diff --git a/include/platform_defs.h.in b/include/platform_defs.h.in index d111ec6d..adb00181 100644 --- a/include/platform_defs.h.in +++ b/include/platform_defs.h.in @@ -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__ */ diff --git a/libfrog/linux.c b/libfrog/linux.c index b6c24879..79bd79eb 100644 --- a/libfrog/linux.c +++ b/libfrog/linux.c @@ -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