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>
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 *);
# define ASSERT(EX) ((void) 0)
#endif
+extern int platform_nproc(void);
+
#endif /* __XFS_PLATFORM_DEFS_H__ */
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