[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/12] virtiofsd: Move core file creation code in separate functio
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 07/12] virtiofsd: Move core file creation code in separate function |
Date: |
Thu, 17 Feb 2022 17:24:55 +0000 |
From: Vivek Goyal <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.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Message-Id: <20220208204813.682906-7-vgoyal@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@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 3e56d1cd95..e27479f1c9 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2001,6 +2001,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)
{
@@ -2010,7 +2034,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);
@@ -2026,18 +2049,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.35.1
- [PULL 11/12] virtiofsd: Add an option to enable/disable security label, (continued)
- [PULL 00/12] virtiofs queue, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 01/12] virtiofsd: Do not support blocking flock, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 02/12] virtiofsd: Fix breakage due to fuse_init_in size change, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 04/12] virtiofsd: Parse extended "struct fuse_init_in", Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 03/12] linux-headers: Update headers to v5.17-rc1, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 05/12] virtiofsd: Extend size of fuse_conn_info->capable and ->want fields, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 06/12] virtiofsd, fuse_lowlevel.c: Add capability to parse security context, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 07/12] virtiofsd: Move core file creation code in separate function,
Dr. David Alan Gilbert (git) <=
- [PULL 08/12] virtiofsd: Add helpers to work with /proc/self/task/tid/attr/fscreate, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 09/12] virtiofsd: Create new file with security context, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 10/12] virtiofsd: Create new file using O_TMPFILE and set security context, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 11/12] virtiofsd: Add an option to enable/disable security label, Dr. David Alan Gilbert (git), 2022/02/17
- [PULL 12/12] virtiofsd: Add basic support for FUSE_SYNCFS request, Dr. David Alan Gilbert (git), 2022/02/17
- Re: [PULL 00/12] virtiofs queue, Peter Maydell, 2022/02/20