Whamcloud - gitweb
LU-6081 user: use random() instead of /dev/urandom
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 3cd39ec..e74cf70 100644 (file)
@@ -4683,29 +4683,16 @@ int llapi_create_volatile_idx(char *directory, int idx, int open_flags)
        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);
@@ -4736,13 +4723,16 @@ int llapi_create_volatile_idx(char *directory, int idx, int open_flags)
  */
 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);