vfs_aio_pthread: use event context and threadpool from user_vfs_evg
authorRalph Boehme <slow@samba.org>
Fri, 13 Jul 2018 14:48:19 +0000 (16:48 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Jul 2018 15:49:07 +0000 (17:49 +0200)
Or the root glue in case we're already root.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_aio_pthread.c

index da1ca534907f16d8c96a64d43d8235339a0b9433..cf5b7f61d5b09cbb94dc646380d2aeb262512026 100644 (file)
@@ -51,7 +51,6 @@ struct aio_open_private_data {
        const char *fname;
        char *dname;
        struct smbd_server_connection *sconn;
-       const struct security_unix_token *ux_tok;
        uint64_t initial_allocation_size;
        /* Returns. */
        int ret_fd;
@@ -140,16 +139,6 @@ static void aio_open_worker(void *private_data)
        struct aio_open_private_data *opd =
                (struct aio_open_private_data *)private_data;
 
-       /* Become the correct credential on this thread. */
-       if (set_thread_credentials(opd->ux_tok->uid,
-                               opd->ux_tok->gid,
-                               (size_t)opd->ux_tok->ngroups,
-                               opd->ux_tok->groups) != 0) {
-               opd->ret_fd = -1;
-               opd->ret_errno = errno;
-               return;
-       }
-
        opd->ret_fd = openat(opd->dir_fd,
                        opd->fname,
                        opd->flags,
@@ -219,13 +208,6 @@ static struct aio_open_private_data *create_private_open_data(const files_struct
        opd->sconn = fsp->conn->sconn;
        opd->initial_allocation_size = fsp->initial_allocation_size;
 
-       /* Copy our current credentials. */
-       opd->ux_tok = copy_unix_token(opd, get_current_utok(fsp->conn));
-       if (opd->ux_tok == NULL) {
-               TALLOC_FREE(opd);
-               return NULL;
-       }
-
        /*
         * Copy the parent directory name and the
         * relative path within it.
@@ -268,6 +250,10 @@ static int open_async(const files_struct *fsp,
 {
        struct aio_open_private_data *opd = NULL;
        struct tevent_req *subreq = NULL;
+       const struct smb_vfs_ev_glue *evg = NULL;
+       struct tevent_context *ev = NULL;
+       struct pthreadpool_tevent *tp = NULL;
+       uid_t uid = -1;
 
        opd = create_private_open_data(fsp, flags, mode);
        if (opd == NULL) {
@@ -275,10 +261,20 @@ static int open_async(const files_struct *fsp,
                return -1;
        }
 
-       subreq = pthreadpool_tevent_job_send(opd,
-                                            fsp->conn->user_ev_ctx,
-                                            fsp->conn->sconn->raw_thread_pool,
-                                            aio_open_worker, opd);
+       evg = fsp->conn->user_vfs_evg;
+
+       uid = get_current_uid(fsp->conn);
+       if (uid == 0) {
+               /*
+                * If we're already running as root,
+                * so the root glue.
+                */
+               evg = smb_vfs_ev_glue_get_root_glue(evg);
+       }
+       ev = smb_vfs_ev_glue_ev_ctx(fsp->conn->user_vfs_evg);
+       tp = smb_vfs_ev_glue_tp_path_safe(fsp->conn->user_vfs_evg);
+
+       subreq = pthreadpool_tevent_job_send(opd, ev, tp, aio_open_worker, opd);
        if (subreq == NULL) {
                return -1;
        }