Add support for specifying UID/GID
authorJens Axboe <jens.axboe@oracle.com>
Tue, 8 Dec 2009 09:10:14 +0000 (10:10 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 8 Dec 2009 09:10:14 +0000 (10:10 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
fio.1
fio.c
fio.h
init.c
options.c

diff --git a/HOWTO b/HOWTO
index 0b40f758bbd3604f5fa9c0572d4296c753072dea..45a96bb1618182c0251fb8a77a4bdfd1ab6e460b 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1015,6 +1015,11 @@ cgroup_weight=int        Set the weight of the cgroup to this value. See
                the documentation that comes with the kernel, allowed values
                are in the range of 100..1000.
 
+uid=int                Instead of running as the invoking user, set the user ID to
+               this value before the thread/process does any work.
+
+gid=int                Set group ID, see uid.
+
 6.0 Interpreting the output
 ---------------------------
 
diff --git a/fio.1 b/fio.1
index 2e0a283d527b9dffeca64221fcbf359e3a892670..dfca43efd9ca0707c563a5395aa31e8bde39399f 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -735,6 +735,13 @@ your system doesn't have it mounted, you can do so with:
 .BI cgroup_weight \fR=\fPint
 Set the weight of the cgroup to this value. See the documentation that comes
 with the kernel, allowed values are in the range of 100..1000.
+.TP
+.BI uid \fR=\fPint
+Instead of running as the invoking user, set the user ID to this value before
+the thread/process does any work.
+.TP
+.BI gid \fR=\fPint
+Set group ID, see \fBuid\fR.
 .SH OUTPUT
 While running, \fBfio\fR will display the status of the created jobs.  For
 example:
diff --git a/fio.c b/fio.c
index 7d4c96a2b8a5045cda742f4be7842deb66529637..728addd614e70aafa2548a7914619052abe06d9f 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1041,6 +1041,15 @@ static void *thread_main(void *data)
         */
        fio_mutex_remove(td->mutex);
 
+       if (td->o.uid != -1U && setuid(td->o.uid)) {
+               td_verror(td, errno, "setuid");
+               goto err;
+       }
+       if (td->o.gid != -1U && setgid(td->o.gid)) {
+               td_verror(td, errno, "setgid");
+               goto err;
+       }
+
        /*
         * May alter parameters that init_io_u() will use, so we need to
         * do this first.
diff --git a/fio.h b/fio.h
index b1af7b1bb8935ddfe1ac384f844a91f6c14e7eb5..3b2dd6edcfd51c74ab20ec0d439b723b88802bcd 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -277,6 +277,9 @@ struct thread_options {
         */
        char *cgroup;
        unsigned int cgroup_weight;
+
+       unsigned int uid;
+       unsigned int gid;
 };
 
 #define FIO_VERROR_SIZE        128
diff --git a/init.c b/init.c
index 873a0ba68e4884f50f457bb0786efe32ca8e1878..95c7efb434ec9c8e17a35493b1e0da81c3e7ef22 100644 (file)
--- a/init.c
+++ b/init.c
@@ -181,6 +181,8 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
        td = &threads[thread_number++];
        *td = *parent;
 
+       td->o.uid = td->o.gid = -1U;
+
        dup_files(td, parent);
        options_mem_dupe(td);
 
index 16908a07710a5e525ba666aa82fa4235c3f6c3c0..f62806289ebc3acdfb90b56bbcebb0fec7056309 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1740,6 +1740,18 @@ static struct fio_option options[] = {
                .minval = 100,
                .maxval = 1000,
        },
+       {
+               .name   = "uid",
+               .type   = FIO_OPT_INT,
+               .off1   = td_var_offset(uid),
+               .help   = "Run job with this user ID",
+       },
+       {
+               .name   = "gid",
+               .type   = FIO_OPT_INT,
+               .off1   = td_var_offset(gid),
+               .help   = "Run job with this group ID",
+       },
        {
                .name = NULL,
        },