char file_path[PATH_MAX];
char filename[PATH_MAX];
int fd;
- int random;
+ int rnumber;
int rc;
- fd = open("/dev/urandom", O_RDONLY);
- if (fd < 0) {
- llapi_error(LLAPI_MSG_ERROR, errno,
- "Cannot open /dev/urandom");
- return -errno;
- }
- rc = read(fd, &random, sizeof(random));
- close(fd);
- if (rc < sizeof(random)) {
- llapi_error(LLAPI_MSG_ERROR, errno,
- "cannot read %zu bytes from /dev/urandom",
- sizeof(random));
- return -errno;
- }
+ rnumber = random();
if (idx == -1)
snprintf(filename, sizeof(filename),
- LUSTRE_VOLATILE_HDR"::%.4X", random);
+ LUSTRE_VOLATILE_HDR"::%.4X", rnumber);
else
snprintf(filename, sizeof(filename),
- LUSTRE_VOLATILE_HDR":%.4X:%.4X", idx, random);
+ LUSTRE_VOLATILE_HDR":%.4X:%.4X", idx, rnumber);
rc = snprintf(file_path, sizeof(file_path),
"%s/%s", directory, filename);
*/
int llapi_fswap_layouts(int fd1, int fd2, __u64 dv1, __u64 dv2, __u64 flags)
{
- struct lustre_swap_layouts lsl;
- int rc;
+ struct lustre_swap_layouts lsl;
+ int rc;
- srandom(time(NULL));
lsl.sl_fd = fd2;
lsl.sl_flags = flags;
- lsl.sl_gid = random();
+
+ do
+ lsl.sl_gid = random();
+ while (lsl.sl_gid == 0);
+
lsl.sl_dv1 = dv1;
lsl.sl_dv2 = dv2;
rc = ioctl(fd1, LL_IOC_LOV_SWAP_LAYOUTS, &lsl);