• Home
  • Raw
  • Download

Lines Matching +full:fs +full:- +full:err

3   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
13 * This is a "high-performance" version of passthrough_ll.c. While
21 * If --nocache is specified, the source directory may be changed
25 * Without --nocache, the source directory is assumed to be modified
30 * including data-loss.
36 * Unless --nocache is specified, is only possible to write to files
54 #include <err.h>
81 #define SFS_DEFAULT_THREADS "-1" // take libfuse value as default
84 /* We are re-using pointers to our `struct sfs_inode` and `struct
103 // the drawback that we can no longer re-use inode numbers, and thus
122 int fd {-1};
144 struct Fs { struct
162 static Fs fs{}; argument
166 (fs.nosplice ? \
173 return fs.root; in get_inode()
176 if(inode->fd == -1) { in get_inode()
192 if (conn->capable & FUSE_CAP_EXPORT_SUPPORT) in sfs_init()
193 conn->want |= FUSE_CAP_EXPORT_SUPPORT; in sfs_init()
195 if (fs.timeout && conn->capable & FUSE_CAP_WRITEBACK_CACHE) in sfs_init()
196 conn->want |= FUSE_CAP_WRITEBACK_CACHE; in sfs_init()
198 if (conn->capable & FUSE_CAP_FLOCK_LOCKS) in sfs_init()
199 conn->want |= FUSE_CAP_FLOCK_LOCKS; in sfs_init()
201 if (fs.nosplice) { in sfs_init()
206 conn->want &= ~FUSE_CAP_SPLICE_READ; in sfs_init()
207 conn->want &= ~FUSE_CAP_SPLICE_WRITE; in sfs_init()
209 if (conn->capable & FUSE_CAP_SPLICE_WRITE) in sfs_init()
210 conn->want |= FUSE_CAP_SPLICE_WRITE; in sfs_init()
211 if (conn->capable & FUSE_CAP_SPLICE_READ) in sfs_init()
212 conn->want |= FUSE_CAP_SPLICE_READ; in sfs_init()
223 if (res == -1) { in sfs_getattr()
227 fuse_reply_attr(req, &attr, fs.timeout); in sfs_getattr()
239 res = fchmod(fi->fh, attr->st_mode); in do_setattr()
243 res = chmod(procname, attr->st_mode); in do_setattr()
245 if (res == -1) in do_setattr()
249 uid_t uid = (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : static_cast<uid_t>(-1); in do_setattr()
250 gid_t gid = (valid & FUSE_SET_ATTR_GID) ? attr->st_gid : static_cast<gid_t>(-1); in do_setattr()
253 if (res == -1) in do_setattr()
258 res = ftruncate(fi->fh, attr->st_size); in do_setattr()
262 res = truncate(procname, attr->st_size); in do_setattr()
264 if (res == -1) in do_setattr()
278 tv[0] = attr->st_atim; in do_setattr()
283 tv[1] = attr->st_mtim; in do_setattr()
286 res = futimens(fi->fh, tv); in do_setattr()
293 res = -1; in do_setattr()
297 if (res == -1) in do_setattr()
316 if (fs.debug) in do_lookup()
320 e->attr_timeout = fs.timeout; in do_lookup()
321 e->entry_timeout = fs.timeout; in do_lookup()
324 if (newfd == -1) in do_lookup()
327 auto res = fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); in do_lookup()
328 if (res == -1) { in do_lookup()
331 if (fs.debug) in do_lookup()
336 if (e->attr.st_dev != fs.src_dev) { in do_lookup()
339 } else if (e->attr.st_ino == FUSE_ROOT_ID) { in do_lookup()
345 SrcId id {e->attr.st_ino, e->attr.st_dev}; in do_lookup()
346 unique_lock<mutex> fs_lock {fs.mutex}; in do_lookup()
349 inode_p = &fs.inodes[id]; in do_lookup()
353 e->ino = reinterpret_cast<fuse_ino_t>(inode_p); in do_lookup()
355 e->generation = inode.generation; in do_lookup()
357 if (inode.fd == -ENOENT) { // found unlinked inode in do_lookup()
358 if (fs.debug) in do_lookup()
359 cerr << "DEBUG: lookup(): inode " << e->attr.st_ino in do_lookup()
366 if (fs.debug) in do_lookup()
367 cerr << "DEBUG: lookup(): inode " << e->attr.st_ino in do_lookup()
372 if (fs.debug) in do_lookup()
382 fs.mutex), but this is of no consequence because at this in do_lookup()
385 inode.src_ino = e->attr.st_ino; in do_lookup()
386 inode.src_dev = e->attr.st_dev; in do_lookup()
389 if (fs.debug) in do_lookup()
397 if (fs.debug) in do_lookup()
398 cerr << "DEBUG: lookup(): created userspace inode " << e->attr.st_ino in do_lookup()
408 auto err = do_lookup(parent, name, &e); in sfs_lookup() local
409 if (err == ENOENT) { in sfs_lookup()
410 e.attr_timeout = fs.timeout; in sfs_lookup()
411 e.entry_timeout = fs.timeout; in sfs_lookup()
414 } else if (err) { in sfs_lookup()
415 if (err == ENFILE || err == EMFILE) in sfs_lookup()
417 fuse_reply_err(req, err); in sfs_lookup()
438 if (res == -1) in mknod_symlink()
480 e.attr_timeout = fs.timeout; in sfs_link()
481 e.entry_timeout = fs.timeout; in sfs_link()
486 if (res == -1) { in sfs_link()
492 if (res == -1) { in sfs_link()
500 if (fs.debug) in sfs_link()
515 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_rmdir()
530 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_rename()
539 if (!fs.timeout) { in sfs_unlink()
541 auto err = do_lookup(parent, name, &e); in sfs_unlink() local
542 if (err) { in sfs_unlink()
543 fuse_reply_err(req, err); in sfs_unlink()
550 if (fs.debug) in sfs_unlink()
553 lock_guard<mutex> g_fs {fs.mutex}; in sfs_unlink()
555 inode.fd = -ENOENT; in sfs_unlink()
564 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_unlink()
577 inode.nlookup -= n; in forget_one()
579 if (fs.debug) in forget_one()
585 if (fs.debug) in forget_one()
588 lock_guard<mutex> g_fs {fs.mutex}; in forget_one()
590 fs.inodes.erase({inode.src_ino, inode.src_dev}); in forget_one()
592 } else if (fs.debug) in forget_one()
615 if (res == -1) in sfs_readlink()
642 return reinterpret_cast<DirHandle*>(fi->fh); in get_dir_handle()
654 // Make Helgrind happy - it can't know that there's an implicit in sfs_opendir()
660 if (fd == -1) in sfs_opendir()
665 d->dp = fdopendir(fd); in sfs_opendir()
666 if(d->dp == nullptr) in sfs_opendir()
669 d->offset = 0; in sfs_opendir()
671 fi->fh = reinterpret_cast<uint64_t>(d); in sfs_opendir()
672 if(fs.timeout) { in sfs_opendir()
673 fi->keep_cache = 1; in sfs_opendir()
674 fi->cache_readdir = 1; in sfs_opendir()
701 int err = 0, count = 0; in do_readdir() local
703 if (fs.debug) in do_readdir()
714 if (offset != d->offset) { in do_readdir()
715 if (fs.debug) in do_readdir()
717 seekdir(d->dp, offset); in do_readdir()
718 d->offset = offset; in do_readdir()
724 entry = readdir(d->dp); in do_readdir()
727 err = errno; in do_readdir()
728 if (fs.debug) in do_readdir()
734 d->offset = entry->d_off; in do_readdir()
735 if (is_dot_or_dotdot(entry->d_name)) in do_readdir()
741 err = do_lookup(ino, entry->d_name, &e); in do_readdir()
742 if (err) in do_readdir()
744 entsize = fuse_add_direntry_plus(req, p, rem, entry->d_name, &e, entry->d_off); in do_readdir()
746 e.attr.st_ino = entry->d_ino; in do_readdir()
747 e.attr.st_mode = entry->d_type << 12; in do_readdir()
748 entsize = fuse_add_direntry(req, p, rem, entry->d_name, &e.attr, entry->d_off); in do_readdir()
752 if (fs.debug) in do_readdir()
760 rem -= entsize; in do_readdir()
762 if (fs.debug) { in do_readdir()
763 cerr << "DEBUG: readdir(): added to buffer: " << entry->d_name in do_readdir()
764 << ", ino " << e.attr.st_ino << ", offset " << entry->d_off << endl; in do_readdir()
767 err = 0; in do_readdir()
771 // any entries yet - otherwise we'd end up with wrong lookup in do_readdir()
774 if (err && rem == size) { in do_readdir()
775 if (err == ENFILE || err == EMFILE) in do_readdir()
777 fuse_reply_err(req, err); in do_readdir()
779 if (fs.debug) in do_readdir()
781 << " entries, curr offset " << d->offset << endl; in do_readdir()
782 fuse_reply_buf(req, buf, size - rem); in do_readdir()
816 (fi->flags | O_CREAT) & ~O_NOFOLLOW, mode); in sfs_create()
817 if (fd == -1) { in sfs_create()
818 auto err = errno; in sfs_create() local
819 if (err == ENFILE || err == EMFILE) in sfs_create()
821 fuse_reply_err(req, err); in sfs_create()
825 fi->fh = fd; in sfs_create()
827 auto err = do_lookup(parent, name, &e); in sfs_create() local
828 if (err) { in sfs_create()
829 if (err == ENFILE || err == EMFILE) in sfs_create()
831 fuse_reply_err(req, err); in sfs_create()
846 int fd = dirfd(get_dir_handle(fi)->dp); in sfs_fsyncdir()
851 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_fsyncdir()
859 when userspace opened write-only */ in sfs_open()
860 if (fs.timeout && (fi->flags & O_ACCMODE) == O_WRONLY) { in sfs_open()
861 fi->flags &= ~O_ACCMODE; in sfs_open()
862 fi->flags |= O_RDWR; in sfs_open()
871 if (fs.timeout && fi->flags & O_APPEND) in sfs_open()
872 fi->flags &= ~O_APPEND; in sfs_open()
878 auto fd = open(buf, fi->flags & ~O_NOFOLLOW); in sfs_open()
879 if (fd == -1) { in sfs_open()
880 auto err = errno; in sfs_open() local
881 if (err == ENFILE || err == EMFILE) in sfs_open()
883 fuse_reply_err(req, err); in sfs_open()
889 fi->keep_cache = (fs.timeout != 0); in sfs_open()
890 fi->noflush = (fs.timeout == 0 && (fi->flags & O_ACCMODE) == O_RDONLY); in sfs_open()
891 fi->fh = fd; in sfs_open()
899 inode.nopen--; in sfs_release()
900 close(fi->fh); in sfs_release()
907 auto res = close(dup(fi->fh)); in sfs_flush()
908 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_flush()
917 res = fdatasync(fi->fh); in sfs_fsync()
919 res = fsync(fi->fh); in sfs_fsync()
920 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_fsync()
929 buf.buf[0].fd = fi->fh; in do_read()
947 out_buf.buf[0].fd = fi->fh; in do_write_buf()
952 fuse_reply_err(req, -res); in do_write_buf()
970 if (res == -1) in sfs_statfs()
986 auto err = posix_fallocate(fi->fh, offset, length); in sfs_fallocate() local
987 fuse_reply_err(req, err); in sfs_fallocate()
994 auto res = flock(fi->fh, op); in sfs_flock()
995 fuse_reply_err(req, res == -1 ? errno : 0); in sfs_flock()
1018 if (ret == -1) in sfs_getxattr()
1027 if (ret == -1) in sfs_getxattr()
1061 if (ret == -1) in sfs_listxattr()
1070 if (ret == -1) in sfs_listxattr()
1096 saverr = ret == -1 ? errno : 0; in sfs_setxattr()
1110 saverr = ret == -1 ? errno : 0; in sfs_removexattr()
1158 cout << "Usage: " << prog_name << " --help\n" in print_usage()
1178 token = s.substr(pos_start, pos_end - pos_start); in string_split()
1205 ("debug-fuse", "Enable libfuse debug messages") in parse_options()
1210 ("single", "Run single-threaded") in parse_options()
1211 ("o", "Mount options (see mount.fuse(5) - only use if you know what " in parse_options()
1213 ("num-threads", "Number of libfuse worker threads", in parse_options()
1214 cxxopts::value<int>()->default_value(SFS_DEFAULT_THREADS)) in parse_options()
1215 ("clone-fd", "use separate fuse device fd for each thread", in parse_options()
1216 cxxopts::value<bool>()->implicit_value(SFS_DEFAULT_CLONE_FD)); in parse_options()
1238 fs.debug = options.count("debug") != 0; in parse_options()
1239 fs.debug_fuse = options.count("debug-fuse") != 0; in parse_options()
1241 fs.foreground = options.count("foreground") != 0; in parse_options()
1242 if (fs.debug || fs.debug_fuse) in parse_options()
1243 fs.foreground = true; in parse_options()
1245 fs.nosplice = options.count("nosplice") != 0; in parse_options()
1246 fs.num_threads = options["num-threads"].as<int>(); in parse_options()
1247 fs.clone_fd = options["clone-fd"].as<bool>(); in parse_options()
1251 fs.source = std::string {resolved_path}; in parse_options()
1274 flattened_mount_opts.push_back("fsname=" + fs.source); in parse_options()
1277 fs.fuse_mount_options = string_join(flattened_mount_opts, ','); in parse_options()
1309 fs.root.fd = -1; in main()
1310 fs.root.nlookup = 9999; in main()
1311 fs.timeout = options.count("nocache") ? 0 : 86400.0; in main()
1314 auto ret = lstat(fs.source.c_str(), &stat); in main()
1315 if (ret == -1) in main()
1316 err(1, "ERROR: failed to stat source (\"%s\")", fs.source.c_str()); in main()
1319 fs.src_dev = stat.st_dev; in main()
1321 fs.root.fd = open(fs.source.c_str(), O_PATH); in main()
1322 if (fs.root.fd == -1) in main()
1323 err(1, "ERROR: open(\"%s\", O_PATH)", fs.source.c_str()); in main()
1328 fuse_opt_add_arg(&args, "-o") || in main()
1329 fuse_opt_add_arg(&args, fs.fuse_mount_options.c_str()) || in main()
1330 (fs.debug_fuse && fuse_opt_add_arg(&args, "-odebug"))) in main()
1335 auto se = fuse_session_new(&args, &sfs_oper, sizeof(sfs_oper), &fs); in main()
1348 if (fs.num_threads != -1) in main()
1349 fuse_loop_cfg_set_idle_threads(loop_config, fs.num_threads); in main()
1354 fuse_daemonize(fs.foreground); in main()