All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: qemu-devel@nongnu.org, virtio-fs@redhat.com
Cc: mszeredi@redhat.com, stefanha@redhat.com, dgilbert@redhat.com,
	vgoyal@redhat.com
Subject: [PATCH v4 6/9] virtiofsd: Move core file creation code in separate function
Date: Mon, 24 Jan 2022 16:24:52 -0500	[thread overview]
Message-ID: <20220124212455.83968-7-vgoyal@redhat.com> (raw)
In-Reply-To: <20220124212455.83968-1-vgoyal@redhat.com>

Move core file creation bits in a separate function. Soon this is going
to get more complex as file creation need to set security context also.
And there will be multiple modes of file creation in next patch.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 36 ++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 64b5b4fbb1..54978b7fae 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1976,6 +1976,30 @@ static int lo_do_open(struct lo_data *lo, struct lo_inode *inode,
     return 0;
 }
 
+static int do_lo_create(fuse_req_t req, struct lo_inode *parent_inode,
+                        const char *name, mode_t mode,
+                        struct fuse_file_info *fi, int* open_fd)
+{
+    int err = 0, fd;
+    struct lo_cred old = {};
+    struct lo_data *lo = lo_data(req);
+
+    err = lo_change_cred(req, &old, lo->change_umask);
+    if (err) {
+        return err;
+    }
+
+    /* Try to create a new file but don't open existing files */
+    fd = openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mode);
+    if (fd == -1) {
+        err = errno;
+    } else {
+        *open_fd = fd;
+    }
+    lo_restore_cred(&old, lo->change_umask);
+    return err;
+}
+
 static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
                       mode_t mode, struct fuse_file_info *fi)
 {
@@ -1985,7 +2009,6 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
     struct lo_inode *inode = NULL;
     struct fuse_entry_param e;
     int err;
-    struct lo_cred old = {};
 
     fuse_log(FUSE_LOG_DEBUG, "lo_create(parent=%" PRIu64 ", name=%s)"
              " kill_priv=%d\n", parent, name, fi->kill_priv);
@@ -2001,18 +2024,9 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
         return;
     }
 
-    err = lo_change_cred(req, &old, lo->change_umask);
-    if (err) {
-        goto out;
-    }
-
     update_open_flags(lo->writeback, lo->allow_direct_io, fi);
 
-    /* Try to create a new file but don't open existing files */
-    fd = openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mode);
-    err = fd == -1 ? errno : 0;
-
-    lo_restore_cred(&old, lo->change_umask);
+    err = do_lo_create(req, parent_inode, name, mode, fi, &fd);
 
     /* Ignore the error if file exists and O_EXCL was not given */
     if (err && (err != EEXIST || (fi->flags & O_EXCL))) {
-- 
2.31.1



WARNING: multiple messages have this Message-ID (diff)
From: Vivek Goyal <vgoyal@redhat.com>
To: qemu-devel@nongnu.org, virtio-fs@redhat.com
Cc: vgoyal@redhat.com
Subject: [Virtio-fs] [PATCH v4 6/9] virtiofsd: Move core file creation code in separate function
Date: Mon, 24 Jan 2022 16:24:52 -0500	[thread overview]
Message-ID: <20220124212455.83968-7-vgoyal@redhat.com> (raw)
In-Reply-To: <20220124212455.83968-1-vgoyal@redhat.com>

Move core file creation bits in a separate function. Soon this is going
to get more complex as file creation need to set security context also.
And there will be multiple modes of file creation in next patch.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 36 ++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 64b5b4fbb1..54978b7fae 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1976,6 +1976,30 @@ static int lo_do_open(struct lo_data *lo, struct lo_inode *inode,
     return 0;
 }
 
+static int do_lo_create(fuse_req_t req, struct lo_inode *parent_inode,
+                        const char *name, mode_t mode,
+                        struct fuse_file_info *fi, int* open_fd)
+{
+    int err = 0, fd;
+    struct lo_cred old = {};
+    struct lo_data *lo = lo_data(req);
+
+    err = lo_change_cred(req, &old, lo->change_umask);
+    if (err) {
+        return err;
+    }
+
+    /* Try to create a new file but don't open existing files */
+    fd = openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mode);
+    if (fd == -1) {
+        err = errno;
+    } else {
+        *open_fd = fd;
+    }
+    lo_restore_cred(&old, lo->change_umask);
+    return err;
+}
+
 static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
                       mode_t mode, struct fuse_file_info *fi)
 {
@@ -1985,7 +2009,6 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
     struct lo_inode *inode = NULL;
     struct fuse_entry_param e;
     int err;
-    struct lo_cred old = {};
 
     fuse_log(FUSE_LOG_DEBUG, "lo_create(parent=%" PRIu64 ", name=%s)"
              " kill_priv=%d\n", parent, name, fi->kill_priv);
@@ -2001,18 +2024,9 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
         return;
     }
 
-    err = lo_change_cred(req, &old, lo->change_umask);
-    if (err) {
-        goto out;
-    }
-
     update_open_flags(lo->writeback, lo->allow_direct_io, fi);
 
-    /* Try to create a new file but don't open existing files */
-    fd = openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mode);
-    err = fd == -1 ? errno : 0;
-
-    lo_restore_cred(&old, lo->change_umask);
+    err = do_lo_create(req, parent_inode, name, mode, fi, &fd);
 
     /* Ignore the error if file exists and O_EXCL was not given */
     if (err && (err != EEXIST || (fi->flags & O_EXCL))) {
-- 
2.31.1


  parent reply	other threads:[~2022-01-24 21:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 21:24 [PATCH v4 0/9] virtiofsd: Add support for file security context at creation Vivek Goyal
2022-01-24 21:24 ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` [PATCH v4 1/9] linux-headers: Update headers to v5.17-rc1 Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-27 17:21   ` Dr. David Alan Gilbert
2022-01-27 17:21     ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-27 18:06     ` Vivek Goyal
2022-01-27 18:06       ` [Virtio-fs] " Vivek Goyal
2022-01-27 19:42       ` Dr. David Alan Gilbert
2022-01-27 19:42         ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-24 21:24 ` [PATCH v4 2/9] virtiofsd: Fix breakage due to fuse_init_in size change Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-27 17:17   ` Dr. David Alan Gilbert
2022-01-27 17:17     ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-24 21:24 ` [PATCH v4 3/9] virtiofsd: Parse extended "struct fuse_init_in" Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-27 17:50   ` Dr. David Alan Gilbert
2022-01-27 17:50     ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-27 18:21     ` Vivek Goyal
2022-01-27 18:21       ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` [PATCH v4 4/9] virtiofsd: Extend size of fuse_conn_info->capable and ->want fields Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-27 17:53   ` Dr. David Alan Gilbert
2022-01-27 17:53     ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-27 18:31     ` Vivek Goyal
2022-01-27 18:31       ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` [PATCH v4 5/9] virtiofsd, fuse_lowlevel.c: Add capability to parse security context Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` Vivek Goyal [this message]
2022-01-24 21:24   ` [Virtio-fs] [PATCH v4 6/9] virtiofsd: Move core file creation code in separate function Vivek Goyal
2022-01-27 19:50   ` Dr. David Alan Gilbert
2022-01-27 19:50     ` [Virtio-fs] " Dr. David Alan Gilbert
2022-01-24 21:24 ` [PATCH v4 7/9] virtiofsd: Create new file with fscreate set Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` [PATCH v4 8/9] virtiofsd: Create new file using O_TMPFILE and set security context Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal
2022-01-24 21:24 ` [PATCH v4 9/9] virtiofsd: Add an option to enable/disable security label Vivek Goyal
2022-01-24 21:24   ` [Virtio-fs] " Vivek Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220124212455.83968-7-vgoyal@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=mszeredi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=virtio-fs@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.