[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 074/111] virtiofsd: extract root inode init into setup_root()
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 074/111] virtiofsd: extract root inode init into setup_root() |
Date: |
Thu, 23 Jan 2020 11:58:04 +0000 |
From: Miklos Szeredi <address@hidden>
Inititialize the root inode in a single place.
Signed-off-by: Miklos Szeredi <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
dgilbert:
with fix suggested by Misono Tomohiro <address@hidden>
Reviewed-by: Misono Tomohiro <address@hidden>
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
tools/virtiofsd/passthrough_ll.c | 35 +++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 33bfb4d1f4..9e7191eb75 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2351,6 +2351,30 @@ static void log_func(enum fuse_log_level level, const
char *fmt, va_list ap)
}
}
+static void setup_root(struct lo_data *lo, struct lo_inode *root)
+{
+ int fd, res;
+ struct stat stat;
+
+ fd = open("/", O_PATH);
+ if (fd == -1) {
+ fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", lo->source);
+ exit(1);
+ }
+
+ res = fstatat(fd, "", &stat, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+ if (res == -1) {
+ fuse_log(FUSE_LOG_ERR, "fstatat(%s): %m\n", lo->source);
+ exit(1);
+ }
+
+ root->is_symlink = false;
+ root->fd = fd;
+ root->ino = stat.st_ino;
+ root->dev = stat.st_dev;
+ root->refcount = 2;
+}
+
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -2426,8 +2450,6 @@ int main(int argc, char *argv[])
if (lo.debug) {
current_log_level = FUSE_LOG_DEBUG;
}
- lo.root.refcount = 2;
-
if (lo.source) {
struct stat stat;
int res;
@@ -2446,7 +2468,6 @@ int main(int argc, char *argv[])
} else {
lo.source = "/";
}
- lo.root.is_symlink = false;
if (!lo.timeout_set) {
switch (lo.cache) {
case CACHE_NEVER:
@@ -2466,13 +2487,6 @@ int main(int argc, char *argv[])
exit(1);
}
- lo.root.fd = open(lo.source, O_PATH);
-
- if (lo.root.fd == -1) {
- fuse_log(FUSE_LOG_ERR, "open(\"%s\", O_PATH): %m\n", lo.source);
- exit(1);
- }
-
se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo);
if (se == NULL) {
goto err_out1;
@@ -2495,6 +2509,7 @@ int main(int argc, char *argv[])
setup_sandbox(&lo, se, opts.syslog);
+ setup_root(&lo, &lo.root);
/* Block until ctrl+c or fusermount -u */
ret = virtio_loop(se);
--
2.24.1
- [PULL 073/111] virtiofsd: fail when parent inode isn't known in lo_do_lookup(), (continued)
- [PULL 073/111] virtiofsd: fail when parent inode isn't known in lo_do_lookup(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 075/111] virtiofsd: passthrough_ll: clean up cache related options, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 077/111] virtiofsd: Clean up inodes on destroy, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 080/111] virtiofsd: cleanup allocated resource in se, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 081/111] virtiofsd: fix memory leak on lo.source, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 079/111] virtiofsd: fix error handling in main(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 078/111] virtiofsd: support nanosecond resolution for file timestamp, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 082/111] virtiofsd: add helper for lo_data cleanup, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 090/111] virtiofsd: make lo_release() atomic, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 089/111] virtiofsd: prevent fv_queue_thread() vs virtio_loop() races, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 074/111] virtiofsd: extract root inode init into setup_root(),
Dr. David Alan Gilbert (git) <=
- [PULL 091/111] virtiofsd: prevent races with lo_dirp_put(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 086/111] Virtiofsd: fix memory leak on fuse queueinfo, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 095/111] virtiofsd: passthrough_ll: fix refcounting on remove/rename, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 101/111] virtiofsd: passthrough_ll: Use cache_readdir for directory open, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 107/111] virtiofsd: add --thread-pool-size=NUM option, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 088/111] virtiofsd: use fuse_lowlevel_is_virtio() in fuse_session_destroy(), Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 087/111] virtiofsd: Support remote posix locks, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 083/111] virtiofsd: Prevent multiply running with same vhost_user_socket, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 085/111] virtiofsd: fix incorrect error handling in lo_do_lookup, Dr. David Alan Gilbert (git), 2020/01/23
- [PULL 071/111] virtiofsd: passthrough_ll: control readdirplus, Dr. David Alan Gilbert (git), 2020/01/23