On 9/25/19 4:37 PM, Darrick J. Wong wrote: > From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > > 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@xxxxxxxxxx> > --- > include/libxfs.h | 1 - > include/platform_defs.h.in | 2 ++ > libfrog/linux.c | 9 ++++++++- > 3 files changed, 10 insertions(+), 2 deletions(-) > > > 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; > } hm, may as well remove the test from libxfs then? int libxfs_nproc(void) { int nr; nr = platform_nproc(); if (nr < 1) nr = 1; return nr; }