From 13c42e03bd18ba454366048d163bdfe43d19fc7a Mon Sep 17 00:00:00 2001 From: jwel Date: Tue, 14 Jun 2022 23:29:19 +0900 Subject: [PATCH] Replace fuse-rs to fuser * `time` library has replaced * `Timespec` is not used after fuse-rs 0.4 * `flags` argument in some function of fuser::Filesystem is `i32` Note that fuser has a problem on the MacOS. https://github.com/cberner/fuser/issues/211 --- Cargo.lock | 250 ++++++++++++++++++++++--------------- Cargo.toml | 4 +- src/catfs/inode.rs | 61 ++++----- src/catfs/mod.rs | 90 ++++++++----- src/catfs/rlibc.rs | 26 ++-- src/evicter/mod.rs | 12 +- src/main.rs | 14 ++- src/pcatfs/mod.rs | 85 ++++++++++--- tests/integration_tests.rs | 35 +++--- 9 files changed, 354 insertions(+), 223 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d79e0a9..6c8e971 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,18 @@ version = 3 [[package]] name = "addr2line" -version = "0.13.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ "gimli", ] [[package]] name = "adler" -version = "0.2.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] @@ -48,18 +48,19 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.51" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1931848a574faa8f7c71a12ea00453ff5effbb5f51afe7f77d7a48cace6ac1" +checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" dependencies = [ "addr2line", - "cfg-if", + "cc", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -83,9 +84,9 @@ checksum = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" @@ -109,11 +110,12 @@ version = "0.9.0" dependencies = [ "backtrace", "chan-signal", + "chrono", "clap", "daemonize", "env_logger", "fd", - "fuse", + "fuser", "generic-array", "itertools", "libc", @@ -122,17 +124,28 @@ dependencies = [ "sha2", "syslog", "threadpool", - "time", "twox-hash", "xattr", ] +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chan" version = "0.1.23" @@ -154,11 +167,24 @@ dependencies = [ "libc", ] +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", @@ -180,9 +206,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.6.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" +checksum = "ecae1c064e29fcabb6c2e9939e53dc7da72ed90234ae36ebfe03a478742efbd1" dependencies = [ "generic-array", ] @@ -224,23 +250,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] -name = "fuse" -version = "0.3.1" +name = "fuser" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e57070510966bfef93662a81cb8aa2b1c7db0964354fa9921434f04b9e8660" +checksum = "74928cf021619b0612e45c3a5332e9a5302c6739b7b5eaecd835ba620c346e0d" dependencies = [ "libc", - "log 0.3.9", + "log 0.4.14", + "page_size", "pkg-config", - "thread-scoped", - "time", + "users", ] [[package]] name = "generic-array" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fceb69994e330afed50c93524be68c42fa898c2d9fd4ee8da03bd7363acd26f2" +checksum = "b2297fb0e3ea512e380da24b52dca3924028f59df5e3a17a18f81d8349ca7ebe" dependencies = [ "nodrop", "typenum", @@ -248,26 +274,26 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.15" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "gimli" -version = "0.22.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" [[package]] name = "hermit-abi" -version = "0.1.16" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -295,9 +321,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.78" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa7087f49d294270db4e1928fc110c976cd4b9e5a16348e0a1df09afa99e6c98" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" [[package]] name = "log" @@ -305,29 +331,29 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.11", + "log 0.4.14", ] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] name = "memchr" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "miniz_oxide" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", "autocfg", @@ -339,11 +365,30 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -351,21 +396,34 @@ dependencies = [ [[package]] name = "object" -version = "0.20.0" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +dependencies = [ + "memchr", +] + +[[package]] +name = "page_size" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" +checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +dependencies = [ + "libc", + "winapi", +] [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" [[package]] name = "ppv-lite86" -version = "0.2.9" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "rand" @@ -392,25 +450,23 @@ dependencies = [ [[package]] name = "rand" -version = "0.7.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "getrandom", "libc", "rand_chacha", - "rand_core 0.5.1", - "rand_hc", + "rand_core 0.6.3", ] [[package]] name = "rand_chacha" -version = "0.2.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", + "rand_core 0.6.3", ] [[package]] @@ -430,22 +486,13 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" -version = "0.5.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -479,9 +526,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "sha2" @@ -496,6 +543,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.8.0" @@ -523,12 +576,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "thread-scoped" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcbb6aa301e5d3b0b5ef639c9a9c7e2f1c944f177b460c04dc24c69b1fa2bd99" - [[package]] name = "thread_local" version = "0.3.6" @@ -549,29 +596,30 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] [[package]] name = "twox-hash" -version = "1.5.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ - "rand 0.7.3", + "cfg-if 1.0.0", + "rand 0.8.5", + "static_assertions", ] [[package]] name = "typenum" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ucd-util" @@ -581,9 +629,9 @@ checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unix_socket" @@ -591,10 +639,20 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", ] +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log 0.4.14", +] + [[package]] name = "utf8-ranges" version = "1.0.4" @@ -609,15 +667,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" diff --git a/Cargo.toml b/Cargo.toml index 26d9ce3..e995f0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ clap = "2.29.0" daemonize = "0.2" env_logger = "0.4" fd = { git = "https://github.com/stemjail/fd-rs.git", rev = "3bc3e3587f8904cce8bf29163a2021c2f5906557" } -fuse = "0.3.0" +fuser = "0.7" generic-array = "0.8" itertools = "0.6" log = "0.3" @@ -25,7 +25,7 @@ rand = "0.3" sha2 = "0.6" syslog = "3.3" threadpool = "1.4" -time = "0.1" +chrono = "0.4" twox-hash = "1.5.0" xattr = "0.2" diff --git a/src/catfs/inode.rs b/src/catfs/inode.rs index 705ab3c..9e6809f 100644 --- a/src/catfs/inode.rs +++ b/src/catfs/inode.rs @@ -1,10 +1,8 @@ -extern crate fuse; +extern crate fuser; extern crate libc; extern crate threadpool; -extern crate time; use self::threadpool::ThreadPool; -use self::time::{Duration, Timespec}; use std::ffi::OsStr; use std::ffi::OsString; @@ -12,6 +10,7 @@ use std::io; use std::os::unix::io::RawFd; use std::path::{Path, PathBuf}; use std::sync::Mutex; +use std::time::{Duration, SystemTime}; use catfs::dir; use catfs::error; @@ -27,22 +26,22 @@ pub struct Inode { name: OsString, path: PathBuf, - attr: fuse::FileAttr, - time: Timespec, + attr: fuser::FileAttr, + time: SystemTime, cache_valid_if_present: bool, flush_failed: bool, refcnt: u64, } -fn to_filetype(t: libc::mode_t) -> fuse::FileType { +fn to_filetype(t: libc::mode_t) -> fuser::FileType { match t & libc::S_IFMT { - libc::S_IFLNK => fuse::FileType::Symlink, - libc::S_IFREG => fuse::FileType::RegularFile, - libc::S_IFBLK => fuse::FileType::BlockDevice, - libc::S_IFDIR => fuse::FileType::Directory, - libc::S_IFCHR => fuse::FileType::CharDevice, - libc::S_IFIFO => fuse::FileType::NamedPipe, + libc::S_IFLNK => fuser::FileType::Symlink, + libc::S_IFREG => fuser::FileType::RegularFile, + libc::S_IFBLK => fuser::FileType::BlockDevice, + libc::S_IFDIR => fuser::FileType::Directory, + libc::S_IFCHR => fuser::FileType::CharDevice, + libc::S_IFIFO => fuser::FileType::NamedPipe, v => panic!("unknown type: {}", v), } } @@ -54,7 +53,7 @@ impl Inode { cache_dir: RawFd, name: OsString, path: PathBuf, - attr: fuse::FileAttr, + attr: fuser::FileAttr, ) -> Inode { return Inode { src_dir: src_dir, @@ -62,7 +61,7 @@ impl Inode { name: name, path: path, attr: attr, - time: time::get_time(), + time: SystemTime::now(), cache_valid_if_present: false, flush_failed: false, refcnt: 1, @@ -75,7 +74,7 @@ impl Inode { } pub fn not_expired(&self, ttl: &Duration) -> bool { - (time::get_time() - self.time) > *ttl + SystemTime::now() > self.time + *ttl } pub fn get_child_name(&self, name: &OsStr) -> PathBuf { @@ -88,11 +87,11 @@ impl Inode { return &self.path; } - pub fn get_attr(&self) -> &fuse::FileAttr { + pub fn get_attr(&self) -> &fuser::FileAttr { return &self.attr; } - pub fn get_kind(&self) -> fuse::FileType { + pub fn get_kind(&self) -> fuser::FileType { return self.attr.kind; } @@ -106,35 +105,25 @@ impl Inode { } } - pub fn lookup_path(dir: RawFd, path: &dyn AsRef) -> io::Result { + pub fn lookup_path(dir: RawFd, path: &dyn AsRef) -> io::Result { let st = rlibc::fstatat(dir, path)?; - let attr = fuse::FileAttr { + let attr = fuser::FileAttr { ino: st.st_ino, size: st.st_size as u64, blocks: st.st_blocks as u64, - atime: Timespec { - sec: st.st_atime as i64, - nsec: st.st_atime_nsec as i32, - }, - mtime: Timespec { - sec: st.st_mtime as i64, - nsec: st.st_mtime_nsec as i32, - }, - ctime: Timespec { - sec: st.st_ctime as i64, - nsec: st.st_ctime_nsec as i32, - }, - crtime: Timespec { - sec: st.st_ctime as i64, - nsec: st.st_ctime_nsec as i32, - }, + atime: SystemTime::UNIX_EPOCH + Duration::from_secs(st.st_atime as u64), + mtime: SystemTime::UNIX_EPOCH + Duration::from_secs(st.st_mtime as u64), + ctime: SystemTime::UNIX_EPOCH + Duration::from_secs(st.st_ctime as u64), + crtime: SystemTime::UNIX_EPOCH + Duration::from_secs(st.st_ctime as u64), kind: to_filetype(st.st_mode), perm: (st.st_mode & !libc::S_IFMT) as u16, nlink: st.st_nlink as u32, uid: st.st_uid, gid: st.st_gid, rdev: st.st_rdev as u32, + blksize: st.st_blksize as u32, flags: 0, + padding: 0 }; return Ok(attr); } @@ -272,7 +261,7 @@ impl Inode { return Ok(()); } - pub fn utimes(&self, atime: &Timespec, mtime: &Timespec, flags: u32) -> io::Result<()> { + pub fn utimes(&self, atime: &SystemTime, mtime: &SystemTime, flags: u32) -> io::Result<()> { rlibc::utimensat(self.src_dir, &self.path, atime, mtime, flags) } diff --git a/src/catfs/mod.rs b/src/catfs/mod.rs index fbd7145..c6d3f63 100644 --- a/src/catfs/mod.rs +++ b/src/catfs/mod.rs @@ -1,12 +1,18 @@ -extern crate fuse; +extern crate fuser; extern crate libc; extern crate threadpool; -extern crate time; -use self::fuse::{ReplyEntry, ReplyAttr, ReplyOpen, ReplyEmpty, ReplyDirectory, ReplyData, - ReplyWrite, ReplyCreate, ReplyStatfs}; - -use self::time::{Duration, Timespec}; +use self::fuser::{ + ReplyEntry, + ReplyAttr, + ReplyOpen, + ReplyEmpty, + ReplyDirectory, + ReplyData,ReplyWrite, + ReplyCreate, + ReplyStatfs, + TimeOrNow +}; use std::cmp; use std::collections::HashMap; @@ -16,6 +22,7 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::io::RawFd; use std::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockWriteGuard}; use std::path::{Path, PathBuf}; +use std::time::{Duration, SystemTime}; use self::threadpool::ThreadPool; @@ -119,7 +126,7 @@ impl CatFS { cache: to.as_ref().to_path_buf(), src_dir: src_dir, cache_dir: cache_dir, - ttl: Duration::zero(), + ttl: Duration::ZERO, store: Mutex::new(Default::default()), dh_store: Mutex::new(Default::default()), fh_store: Mutex::new(Default::default()), @@ -146,7 +153,7 @@ impl CatFS { PathBuf::new(), root_attr, ); - inode.use_ino(fuse::FUSE_ROOT_ID); + inode.use_ino(fuser::FUSE_ROOT_ID); self.insert_inode(inode); @@ -184,8 +191,8 @@ impl CatFS { store.inodes_cache.remove(path); } - fn ttl_now(&self) -> time::Timespec { - return time::get_time() + self.ttl; + fn ttl_now(&self) -> Duration { + return SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap() + self.ttl; } pub fn statfs(&mut self, _ino: u64, reply: ReplyStatfs) { @@ -343,12 +350,13 @@ impl CatFS { uid: Option, gid: Option, size: Option, - atime: Option, - mtime: Option, + atime: Option, + mtime: Option, + _ctime: Option, fh: Option, - crtime: Option, - chgtime: Option, - bkuptime: Option, + crtime: Option, + chgtime: Option, + bkuptime: Option, flags: Option, reply: ReplyAttr, ) { @@ -435,6 +443,22 @@ impl CatFS { if mtime.is_some() || atime.is_some() { let old_attr = inode.get_attr(); + let mtime = match mtime { + Some(time_or_now) => match time_or_now { + TimeOrNow::SpecificTime(time) => Some(time), + TimeOrNow::Now => Some(SystemTime::now()), + }, + None => None, + }; + + let atime = match atime { + Some(time_or_now) => match time_or_now { + TimeOrNow::SpecificTime(time) => Some(time), + TimeOrNow::Now => Some(SystemTime::now()), + }, + None => None, + }; + if let Err(e) = inode.utimes( &atime.unwrap_or(old_attr.atime), &mtime.unwrap_or(old_attr.mtime), @@ -504,7 +528,7 @@ impl CatFS { } } - pub fn opendir(&mut self, ino: u64, flags: u32, reply: ReplyOpen) { + pub fn opendir(&mut self, ino: u64, flags: i32, reply: ReplyOpen) { let inode: Arc>; { let store = self.store.lock().unwrap(); @@ -518,7 +542,7 @@ impl CatFS { let dh = dh_store.next_id; dh_store.next_id += 1; dh_store.handles.insert(dh, dir); - reply.opened(dh, flags); + reply.opened(dh, flags as u32); debug!("<-- opendir {:?} = {}", inode.get_path(), dh); } Err(e) => { @@ -561,14 +585,14 @@ impl CatFS { reply.ok(); } - pub fn releasedir(&mut self, _ino: u64, dh: u64, _flags: u32, reply: ReplyEmpty) { + pub fn releasedir(&mut self, _ino: u64, dh: u64, _flags: i32, reply: ReplyEmpty) { let mut dh_store = self.dh_store.lock().unwrap(); // the handle will be destroyed and closed dh_store.handles.remove(&dh); reply.ok(); } - pub fn open(&mut self, ino: u64, flags: u32, reply: ReplyOpen) { + pub fn open(&mut self, ino: u64, flags: i32, reply: ReplyOpen) { let inode: Arc>; { let store = self.store.lock().unwrap(); @@ -576,13 +600,13 @@ impl CatFS { } let mut inode = inode.write().unwrap(); - match inode.open(flags, &self.tp) { + match inode.open(flags as u32, &self.tp) { Ok(file) => { let mut fh_store = self.fh_store.lock().unwrap(); let fh = fh_store.next_id; fh_store.next_id += 1; fh_store.handles.insert(fh, Arc::new(Mutex::new(file))); - reply.opened(fh, flags); + reply.opened(fh, flags as u32); debug!("<-- open {:?} = {}", inode.get_path(), fh); } Err(e) => { @@ -592,7 +616,16 @@ impl CatFS { } } - pub fn read(&mut self, _ino: u64, fh: u64, offset: i64, size: u32, reply: ReplyData) { + pub fn read( + &mut self, + _ino: u64, + fh: u64, + offset: i64, + size: u32, + _flags: i32, + _lock_owner: Option, + reply: ReplyData + ) { let file: Arc>; { let fh_store = self.fh_store.lock().unwrap(); @@ -617,7 +650,8 @@ impl CatFS { parent: u64, name: OsString, mode: u32, - flags: u32, + _umask: u32, + flags: i32, reply: ReplyCreate, ) { let parent_inode: Arc>; @@ -640,7 +674,7 @@ impl CatFS { let attr = *inode.get_attr(); debug!("<-- create {:?} = {}", inode.get_path(), fh); self.insert_inode(inode); - reply.created(&self.ttl_now(), &attr, 0, fh, flags); + reply.created(&self.ttl_now(), &attr, 0, fh, flags as u32); } Err(e) => { error!( @@ -659,7 +693,7 @@ impl CatFS { fh: u64, offset: i64, data: Vec, - _flags: u32, + _flags: i32, reply: ReplyWrite, ) { let nwritten: usize; @@ -781,8 +815,8 @@ impl CatFS { &mut self, _ino: u64, fh: u64, - _flags: u32, - _lock_owner: u64, + _flags: i32, + _lock_owner: Option, _flush: bool, reply: ReplyEmpty, ) { @@ -834,7 +868,7 @@ impl CatFS { } } - pub fn mkdir(&mut self, parent: u64, name: OsString, mode: u32, reply: ReplyEntry) { + pub fn mkdir(&mut self, parent: u64, name: OsString, mode: u32, _umask: u32, reply: ReplyEntry) { let parent_inode: Arc>; { let store = self.store.lock().unwrap(); diff --git a/src/catfs/rlibc.rs b/src/catfs/rlibc.rs index 984ce43..4ce710c 100644 --- a/src/catfs/rlibc.rs +++ b/src/catfs/rlibc.rs @@ -1,6 +1,5 @@ -extern crate fuse; +extern crate fuser; extern crate libc; -extern crate time; extern crate xattr; use std::ffi::{CStr, CString, OsStr, OsString}; @@ -9,19 +8,18 @@ use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::io; use std::mem::MaybeUninit; use std::path::Path; -#[cfg(not(target_os = "macos"))] use std::ptr; use std::os::unix::io::AsRawFd; use std::os::unix::io::RawFd; use std::os::unix::fs::FileExt; +use std::time::SystemTime; -use self::fuse::FileType; -use self::time::Timespec; +use self::fuser::FileType; use self::xattr::FileExt as XattrFileExt; -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_pointer_width = "32")))] use self::libc::{fstat64, fstatvfs64, ftruncate64, open64, openat64, pread64, pwrite64, stat64, statvfs64}; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_pointer_width = "32"))] use self::libc::{fstat as fstat64, fstatvfs as fstatvfs64, ftruncate as ftruncate64, open as open64, openat as openat64, pread as pread64, pwrite as pwrite64, stat as stat64, statvfs as statvfs64}; use catfs::error; @@ -162,7 +160,7 @@ impl Dirent { #[cfg(target_os = "macos")] return self.en.d_seekoff as i64; } - pub fn kind(&self) -> fuse::FileType { + pub fn kind(&self) -> fuser::FileType { match self.en.d_type { libc::DT_BLK => return FileType::BlockDevice, libc::DT_CHR => return FileType::CharDevice, @@ -365,19 +363,19 @@ pub fn utimes(path: &dyn AsRef, atime: libc::time_t, mtime: libc::time_t) pub fn utimensat( dir: RawFd, path: &dyn AsRef, - atime: &Timespec, - mtime: &Timespec, + atime: &SystemTime, + mtime: &SystemTime, flags: u32, ) -> io::Result<()> { let s = to_cstring(path); let mut times = [ libc::timespec { - tv_sec: atime.sec as libc::time_t, - tv_nsec: atime.nsec as libc::c_long, + tv_sec: atime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as libc::time_t, + tv_nsec: atime.duration_since(SystemTime::UNIX_EPOCH).unwrap().subsec_nanos() as libc::c_long, }, libc::timespec { - tv_sec: mtime.sec as libc::time_t, - tv_nsec: mtime.nsec as libc::c_long, + tv_sec: mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as libc::time_t, + tv_nsec: mtime.duration_since(SystemTime::UNIX_EPOCH).unwrap().subsec_nanos() as libc::c_long, }, ]; diff --git a/src/evicter/mod.rs b/src/evicter/mod.rs index 0704c77..47c3d6a 100644 --- a/src/evicter/mod.rs +++ b/src/evicter/mod.rs @@ -24,10 +24,14 @@ use self::dir_walker::DirWalker; use self::itertools::Itertools; use self::twox_hash::XxHash; -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_pointer_width = "32")))] use self::libc::statvfs64; -#[cfg(target_os = "macos")] +#[cfg(not(any(target_os = "macos", target_pointer_width = "32")))] +type fsblkcnt_t = u64; +#[cfg(any(target_os = "macos", target_pointer_width = "32"))] use self::libc::{statvfs as statvfs64}; +#[cfg(any(target_os = "macos", target_pointer_width = "32"))] +type fsblkcnt_t = libc::fsblkcnt_t; pub struct Evicter { dir: RawFd, @@ -381,7 +385,7 @@ mod tests { st.f_blocks = 100; // want 1 free block at beginning. cache_size is 5 * 4K blocks so pretend // 94 blocks are used by other things - st.f_bfree = st.f_blocks as u64 - cache_size / (st.f_frsize as u64) - 94; + st.f_bfree = (st.f_blocks as u64 - cache_size / (st.f_frsize as u64) - 94) as fsblkcnt_t; return Ok(st); } @@ -417,7 +421,7 @@ mod tests { st.f_blocks = 100; // want 1 free block at beginning. cache_size is 5 * 4K blocks so pretend // 94 blocks are used by other things - st.f_bfree = st.f_blocks as u64 - cache_size / (st.f_frsize as u64) - 94; + st.f_bfree = (st.f_blocks as u64 - cache_size / (st.f_frsize as u64) - 94) as fsblkcnt_t; return Ok(st); } diff --git a/src/main.rs b/src/main.rs index 1276016..6fc4138 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,12 @@ extern crate chan_signal; extern crate clap; extern crate daemonize; extern crate env_logger; -extern crate fuse; +extern crate fuser; extern crate libc; #[macro_use] extern crate log; extern crate syslog; -extern crate time; +extern crate chrono; use std::env; use std::ffi::{OsStr, OsString}; @@ -18,6 +18,7 @@ use std::path::Path; use std::str::FromStr; use std::sync::{Arc, Mutex}; use std::thread; +use std::time; use chan_signal::Signal; use clap::{App, Arg}; @@ -25,6 +26,8 @@ use daemonize::{Daemonize}; use env_logger::LogBuilder; use log::LogRecord; use syslog::{Facility,Severity}; +use chrono::offset::Local; +use chrono::DateTime; mod pcatfs; mod catfs; @@ -47,7 +50,8 @@ static mut SYSLOGGER: Option> = None; fn main_internal() -> error::Result<()> { let format = |record: &LogRecord| { - let t = time::now(); + let t = time::SystemTime::now(); + let t = DateTime::::from(t); let syslog: bool; unsafe { syslog = SYSLOG; @@ -55,7 +59,7 @@ fn main_internal() -> error::Result<()> { if !syslog { format!( "{} {:5} - {}", - time::strftime("%Y-%m-%d %H:%M:%S", &t).unwrap(), + t.format("%Y-%m-%d %H:%M:%S"), record.level(), record.args() ) @@ -244,7 +248,7 @@ fn main_internal() -> error::Result<()> { debug!("options are {:?}", flags.mount_options); { - let mut session = fuse::Session::new(fs, Path::new(&flags.mount_point), &options)?; + let mut session = fuser::Session::new(fs, Path::new(&flags.mount_point), &options)?; let need_unmount = Arc::new(Mutex::new(true)); let need_unmount2 = need_unmount.clone(); thread::spawn(move || { diff --git a/src/pcatfs/mod.rs b/src/pcatfs/mod.rs index a6b8433..221f6d5 100644 --- a/src/pcatfs/mod.rs +++ b/src/pcatfs/mod.rs @@ -1,14 +1,28 @@ -extern crate fuse; +extern crate fuser; extern crate threadpool; -extern crate time; -use self::fuse::{Filesystem, Request, ReplyEntry, ReplyAttr, ReplyOpen, ReplyEmpty, - ReplyDirectory, ReplyData, ReplyWrite, ReplyCreate, ReplyStatfs}; +use self::fuser::{ + Filesystem, + Request, + ReplyEntry, + ReplyAttr, + ReplyOpen, + ReplyEmpty,ReplyDirectory, + ReplyData, + ReplyWrite, + ReplyCreate, + ReplyStatfs, + TimeOrNow +}; + +//use self::fuser::ll::TimeOrNow; + use self::threadpool::ThreadPool; -use self::time::Timespec; use std::ffi::OsStr; use std::ops::Deref; +use std::time::SystemTime; + use catfs::CatFS; @@ -82,7 +96,9 @@ impl Filesystem for PCatFS { fh: u64, offset: i64, data: &[u8], - _flags: u32, + _write_flags: u32, + _flags: i32, + _lock_owner: Option, reply: ReplyWrite, ) { let s = make_self(self); @@ -92,7 +108,6 @@ impl Filesystem for PCatFS { }); } - fn rename( &mut self, _req: &Request, @@ -100,6 +115,7 @@ impl Filesystem for PCatFS { name: &OsStr, newparent: u64, newname: &OsStr, + _flags: u32, reply: ReplyEmpty, ) { let s = make_self(self); @@ -117,7 +133,9 @@ impl Filesystem for PCatFS { run_in_threadpool!{ fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) { } + } + run_in_threadpool!{ fn setattr( &mut self, _req: &Request, @@ -126,20 +144,25 @@ impl Filesystem for PCatFS { uid: Option, gid: Option, size: Option, - atime: Option, - mtime: Option, + atime: Option, + mtime: Option, + ctime: Option, fh: Option, - crtime: Option, - chgtime: Option, - bkuptime: Option, + crtime: Option, + chgtime: Option, + bkuptime: Option, flags: Option, reply: ReplyAttr, ) { } + } - fn opendir(&mut self, _req: &Request, ino: u64, flags: u32, reply: ReplyOpen) { + run_in_threadpool!{ + fn opendir(&mut self, _req: &Request, ino: u64, flags: i32, reply: ReplyOpen) { } + } + run_in_threadpool!{ fn readdir( &mut self, _req: &Request, @@ -149,13 +172,19 @@ impl Filesystem for PCatFS { reply: ReplyDirectory, ) { } + } - fn releasedir(&mut self, _req: &Request, _ino: u64, dh: u64, _flags: u32, reply: ReplyEmpty) { + run_in_threadpool!{ + fn releasedir(&mut self, _req: &Request, _ino: u64, dh: u64, _flags: i32, reply: ReplyEmpty) { } + } - fn open(&mut self, _req: &Request, ino: u64, flags: u32, reply: ReplyOpen) { + run_in_threadpool!{ + fn open(&mut self, _req: &Request, ino: u64, flags: i32, reply: ReplyOpen) { } + } + run_in_threadpool!{ fn read( &mut self, _req: &Request, @@ -163,25 +192,33 @@ impl Filesystem for PCatFS { fh: u64, offset: i64, size: u32, + flags: i32, + lock_owner: Option, reply: ReplyData, ) { } + } + run_in_threadpool!{ fn flush(&mut self, _req: &Request, ino: u64, fh: u64, _lock_owner: u64, reply: ReplyEmpty) { } + } + run_in_threadpool!{ fn release( &mut self, _req: &Request, _ino: u64, fh: u64, - _flags: u32, - _lock_owner: u64, + _flags: i32, + _lock_owner: Option, _flush: bool, reply: ReplyEmpty, ) { } + } + run_in_threadpool!{ fn statfs(&mut self, _req: &Request, ino: u64, reply: ReplyStatfs) { } } @@ -189,26 +226,34 @@ impl Filesystem for PCatFS { run_in_threadpool!{ fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) { } + } + run_in_threadpool!{ fn create( &mut self, _req: &Request, parent: u64, name: &OsStr, mode: u32, - flags: u32, + umask: u32, + flags: i32, reply: ReplyCreate, ) { } + } + run_in_threadpool!{ fn unlink(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEmpty) { } + } - + run_in_threadpool!{ fn rmdir(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEmpty) { } + } - fn mkdir(&mut self, _req: &Request, parent: u64, name: &OsStr, mode: u32, reply: ReplyEntry) { + run_in_threadpool!{ + fn mkdir(&mut self, _req: &Request, parent: u64, name: &OsStr, mode: u32, umask: u32, reply: ReplyEntry) { } } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 34ff05c..b62c160 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -3,12 +3,13 @@ extern crate log; extern crate libc; extern crate env_logger; -extern crate fuse; -extern crate time; +extern crate fuser; extern crate xattr; +extern crate chrono; use std::env; use std::ffi::{OsStr, OsString}; +use std::os::unix::ffi::OsStrExt; use std::fs; use std::fs::{File, OpenOptions}; use std::io; @@ -16,9 +17,12 @@ use std::io::{Read, Seek, Write}; use std::process::{Command, Stdio}; use std::path::{Path, PathBuf}; use std::os::unix::fs::FileExt; +use std::time; use env_logger::LogBuilder; use log::LogRecord; +use chrono::offset::Local; +use chrono::DateTime; extern crate catfs; @@ -42,17 +46,17 @@ trait Fixture { fn teardown(self) -> error::Result<()>; } -struct CatFSTests<'a> { +struct CatFSTests { prefix: PathBuf, mnt: PathBuf, src: PathBuf, cache: PathBuf, - session: Option>, + session: Option, evicter: Option, - nested: Option>>, + nested: Option>, } -impl<'a> CatFSTests<'a> { +impl CatFSTests { fn get_orig_dir() -> PathBuf { let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap(); return PathBuf::from(manifest).join("tests/resources"); @@ -66,14 +70,14 @@ impl<'a> CatFSTests<'a> { return self.cache.clone(); } - fn mount(&self) -> error::Result<(fuse::BackgroundSession<'a>, Evicter)> { + fn mount(&self) -> error::Result<(fuser::BackgroundSession, Evicter)> { let fs = CatFS::new(&self.src, &self.cache)?; let fs = PCatFS::new(fs); let cache_dir = fs.get_cache_dir()?; // essentially no-op, but ensures that it starts and terminates let ev = Evicter::new(cache_dir, &DiskSpace::Bytes(1)); - return Ok((unsafe { fuse::spawn_mount(fs, &self.mnt, &[])? }, ev)); + return Ok((unsafe { fuser::spawn_mount(fs, &self.mnt, &[])? }, ev)); } fn assert_cache_valid(&self, path: &dyn AsRef) { @@ -86,13 +90,14 @@ impl<'a> CatFSTests<'a> { } } -impl<'a> Fixture for CatFSTests<'a> { - fn setup() -> error::Result> { +impl Fixture for CatFSTests { + fn setup() -> error::Result { let format = |record: &LogRecord| { - let t = time::now(); + let t = time::SystemTime::now(); + let t = DateTime::::from(t); format!( "{} {:5} - {}", - time::strftime("%Y-%m-%d %H:%M:%S", &t).unwrap(), + t.format("%Y-%m-%d %H:%M:%S"), record.level(), record.args() ) @@ -141,7 +146,7 @@ impl<'a> Fixture for CatFSTests<'a> { fs::create_dir_all(&mnt2)?; fs::create_dir_all(&cache2)?; - + let t2 = CatFSTests { prefix: t.prefix.clone(), mnt: mnt2, @@ -232,7 +237,7 @@ unit_tests!{ .stderr(Stdio::null()) .status().expect("failed to execute `dd'"); assert!(status.success()); - + let foo = fs::symlink_metadata(&f.get_from().join("foo")).unwrap(); assert_eq!(foo.len(), 10 * 1024 * 1024); diff(&f.get_from(), &f.mnt); @@ -370,7 +375,7 @@ unit_tests!{ return; } } - + let foo = f.src.join("file1"); xattr::set(&foo, "user.catfs.random", b"hello").unwrap(); rlibc::utimes(&foo, 0, 100000000).unwrap();