Whamcloud - gitweb
LU-6081 user: use random() instead of /dev/urandom
[fs/lustre-release.git] / lustre / utils / lfs.c
index dbb27eb..3c41251 100644 (file)
@@ -353,41 +353,6 @@ command_t cmdlist[] = {
        { 0, 0, 0, NULL }
 };
 
-/* Generate a random id for the grouplock */
-static int random_group_id(int *gid)
-{
-       int     fd;
-       int     rc;
-       size_t  sz = sizeof(*gid);
-
-       fd = open("/dev/urandom", O_RDONLY);
-       if (fd < 0) {
-               rc = -errno;
-               fprintf(stderr, "cannot open /dev/urandom: %s\n",
-                       strerror(-rc));
-               goto out;
-       }
-
-retry:
-       rc = read(fd, gid, sz);
-       if (rc < sz) {
-               rc = -errno;
-               fprintf(stderr, "cannot read %zu bytes from /dev/urandom: %s\n",
-                       sz, strerror(-rc));
-               goto out;
-       }
-
-       /* gids must be non-zero */
-       if (*gid == 0)
-               goto retry;
-
-out:
-       if (fd >= 0)
-               close(fd);
-
-       return rc;
-}
-
 #define MIGRATION_BLOCKS 1
 
 static int lfs_migrate(char *name, __u64 migration_flags,
@@ -433,15 +398,6 @@ static int lfs_migrate(char *name, __u64 migration_flags,
                goto free;
        }
 
-       if (migration_flags & MIGRATION_BLOCKS) {
-               rc = random_group_id(&gid);
-               if (rc < 0) {
-                       fprintf(stderr, "%s: cannot get random group ID: %s\n",
-                               name, strerror(-rc));
-                       goto free;
-               }
-       }
-
        /* search for file directory pathname */
        if (strlen(name) > sizeof(parent)-1) {
                rc = -E2BIG;
@@ -526,6 +482,9 @@ static int lfs_migrate(char *name, __u64 migration_flags,
                goto error;
        }
 
+       do
+               gid = random();
+       while (gid == 0);
        if (migration_flags & MIGRATION_BLOCKS) {
                /* take group lock to limit concurent access
                 * this will be no more needed when exclusive access will
@@ -870,7 +829,7 @@ static int lfs_setstripe(int argc, char **argv)
                if (result) {
                        fprintf(stderr, "error: %s: bad stripe size '%s'\n",
                                argv[0], stripe_size_arg);
-                       return result;
+                       return CMD_HELP;
                }
        }
         /* get the stripe offset */
@@ -4070,6 +4029,10 @@ int main(int argc, char **argv)
 {
         int rc;
 
+       /* Ensure that liblustreapi constructor has run */
+       if (!liblustreapi_initialized)
+               fprintf(stderr, "liblustreapi was not properly initialized\n");
+
         setlinebuf(stdout);
 
        Parser_init("lfs > ", cmdlist);