Compare commits

...
74 Commits
Author SHA1 Message Date
Antonio SJ Musumeci f0f8e527b4 Merge pull request #301 from trapexit/time
make futimes crossplatform
2016-08-07 14:46:43 -04:00
Antonio SJ Musumeci 49474f01ca make futimes crossplatform 2016-08-07 14:42:54 -04:00
Antonio SJ Musumeci 9e8b309a90 Merge pull request #300 from trapexit/fuseversion
bump FUSE_USE_VERSION to 29
2016-08-04 17:15:37 -04:00
Antonio SJ Musumeci f7547d7cf5 Merge pull request #299 from trapexit/realpath
use dynamic buffer for realpath
2016-08-04 17:14:09 -04:00
Antonio SJ Musumeci bb02ab2cba Merge pull request #298 from trapexit/fssendfile
split sendfile wrapper into separate files
2016-08-04 17:13:28 -04:00
Antonio SJ Musumeci fb1432e14e Merge pull request #297 from trapexit/fsattr
make fs_attr compile on unsupported platforms
2016-08-04 17:12:33 -04:00
Antonio SJ Musumeci 34d38cb0fb split sendfile wrapper into separate files 2016-08-04 17:11:23 -04:00
Antonio SJ Musumeci 192a9d54d1 make fs_attr compile on unsupported platforms 2016-08-04 17:10:02 -04:00
Antonio SJ Musumeci 40574bd138 use dynamic buffer for realpath 2016-08-04 14:52:27 -04:00
Antonio SJ Musumeci 064fd5560f bump FUSE_USE_VERSION to 29 2016-08-04 14:02:59 -04:00
Antonio SJ Musumeci 073d1b6f6f Merge pull request #296 from trapexit/fallocate
add osx version of fallocate
2016-08-02 23:46:21 -04:00
Antonio SJ Musumeci 45f757dc60 add osx version of fallocate 2016-08-02 17:14:45 -04:00
Antonio SJ Musumeci 939b4a0fe5 Merge pull request #294 from trapexit/eprand
add epall and eprand policies
2016-08-02 11:29:20 -04:00
Antonio SJ Musumeci 0fceb8e0a3 add epall and eprand policies 2016-08-01 16:08:02 -04:00
Antonio SJ Musumeci 34662da806 Merge pull request #293 from trapexit/faccessat
replace nonstandard eaccess with POSIX.1-2008 faccessat
2016-07-29 12:48:08 -04:00
Antonio SJ Musumeci 7634eb1440 replace nonstandard eaccess with POSIX.1-2008 faccessat 2016-07-29 12:39:44 -04:00
Antonio SJ Musumeci 08cd5f89ff Merge pull request #291 from trapexit/typo
fix typo and clarify feature
2016-07-26 09:09:31 -04:00
Antonio SJ Musumeci 47f184a944 fix typo and clarify feature 2016-07-26 09:09:10 -04:00
Antonio SJ Musumeci 920f7fd049 Merge pull request #290 from trapexit/epff
add existing path first found policy. closes #289
2016-07-11 20:50:32 -04:00
Antonio SJ Musumeci a93ab6c2f5 add existing path first found policy. closes #289 2016-07-11 20:42:56 -04:00
Antonio SJ Musumeci a375f33eb4 Merge pull request #288 from trapexit/uint64_t
move size calculations to use uint64_t. fixes #287
2016-07-11 09:14:14 -04:00
Antonio SJ Musumeci 1e7b84f7fd Merge pull request #285 from waldyrious/patch-1
add license title
2016-07-11 09:13:36 -04:00
Antonio SJ Musumeci 43cbd9c670 move size calculations to use uint64_t. fixes #287 2016-07-11 09:04:47 -04:00
Waldir Pimenta 9f36eada14 add license title
It's not strictly required, but it's useful metadata, and part of the recommended license template text (see http://choosealicense.com/licenses/isc/ and https://opensource.org/licenses/isc-license)
2016-07-01 00:28:12 +01:00
Antonio SJ Musumeci 30cdfa64b8 reiterate path preserving policies 2016-06-07 20:51:18 -04:00
Antonio SJ Musumeci 81e9544f7d Merge pull request #281 from trapexit/update-man
update man page
2016-05-19 17:30:07 -04:00
Antonio SJ Musumeci 3cb2045ebb update man page 2016-05-19 17:28:37 -04:00
Antonio SJ Musumeci 652440fd8c Merge pull request #280 from trapexit/mmapbug
update info on mmap bug and when it was fixed
2016-05-17 16:09:38 -04:00
Antonio SJ Musumeci 6dc6fde641 update info on mmap bug and when it was fixed 2016-05-17 16:09:22 -04:00
Antonio SJ Musumeci 66fdcc4ef7 Merge pull request #279 from trapexit/fallocate
rework fallocate logic
2016-05-11 13:23:33 -04:00
Antonio SJ Musumeci cb35a374ac rework fallocate logic 2016-05-11 13:19:44 -04:00
Antonio SJ Musumeci 68210d9252 Merge pull request #278 from trapexit/ioctl-dir
fix ioctl on directories
2016-05-11 13:12:50 -04:00
Antonio SJ Musumeci 23b8e4582e fix ioctl on directories 2016-05-11 11:22:00 -04:00
Antonio SJ Musumeci 13511ea72a Merge pull request #275 from trapexit/updateman
update man page
2016-05-07 15:19:34 -04:00
Antonio SJ Musumeci 3a50344cb9 update man page 2016-05-07 15:18:48 -04:00
Antonio SJ Musumeci 9f27ad448a Merge pull request #274 from trapexit/lus
add least used space and existing path, least used space policies
2016-05-07 15:17:58 -04:00
Antonio SJ Musumeci be6341e6f0 create eplus (existing path, least used space) policy. closes #273 2016-05-07 15:15:51 -04:00
Antonio SJ Musumeci f7d3e8bf47 create lus (least used space) policy. closes #273 2016-05-07 14:59:42 -04:00
Antonio SJ Musumeci e541cdb755 Merge pull request #272 from trapexit/faq-direct-reads
faq update on direct writes
2016-05-03 11:44:24 -04:00
Antonio SJ Musumeci 74ed1b09ee faq update on direct writes 2016-05-03 11:44:04 -04:00
Antonio SJ Musumeci 9987111fa4 Merge pull request #271 from trapexit/fstabdocs
clean up information regarding fstab
2016-04-27 07:13:28 -04:00
Antonio SJ Musumeci d0414d7c78 clean up information regarding fstab 2016-04-27 07:13:05 -04:00
Antonio SJ Musumeci 8f6a7ba79a Merge pull request #270 from trapexit/fsname
add fsname to readme
2016-04-25 16:58:27 -04:00
Antonio SJ Musumeci ef8d8f306e add fsname to readme 2016-04-25 16:58:18 -04:00
Antonio SJ Musumeci 1de01684e0 Merge pull request #269 from trapexit/createcatdesc
further tweak language regarding policies wrt create category
2016-04-13 13:06:49 -04:00
Antonio SJ Musumeci cd15b7a66a further tweak language regarding policies wrt create category 2016-04-13 13:06:35 -04:00
Antonio SJ Musumeci 6b88258d81 Merge pull request #268 from trapexit/policy-desc
make policy descriptions more explicit
2016-04-13 12:46:26 -04:00
Antonio SJ Musumeci 8643d35ebf make policy descriptions more explicit 2016-04-13 12:45:49 -04:00
Antonio SJ Musumeci b7d7ace9bf Merge pull request #266 from trapexit/tweakreadme
tweak doc language
2016-04-06 14:57:21 -04:00
Antonio SJ Musumeci 1cfe1c3715 tweak doc language 2016-04-06 14:57:02 -04:00
Antonio SJ Musumeci 63b02b327b Merge pull request #265 from trapexit/mmap-bug
add details of mmap cache bug
2016-04-03 16:57:06 -04:00
Antonio SJ Musumeci dbb13ef7ad add details of mmap cache bug 2016-04-03 16:56:47 -04:00
Antonio SJ Musumeci 6aec6c939a Merge pull request #263 from trapexit/dualmount
add dual mount suggestion to mmap problem
2016-03-15 16:45:06 -04:00
Antonio SJ Musumeci 90ca14afff add dual mount suggestion to mmap problem 2016-03-15 16:44:49 -04:00
Antonio SJ Musumeci c7328293a0 Merge pull request #262 from trapexit/mmap-direct_io
add details regarding rtorrent, mmap, and direct_io
2016-03-15 08:25:06 -04:00
Antonio SJ Musumeci cfaf812c62 add details regarding rtorrent, mmap, and direct_io 2016-03-15 08:24:35 -04:00
Antonio SJ Musumeci 47fb6e29c6 Merge pull request #259 from trapexit/dedup-tool
update readme to include mergerfs.dedup
2016-03-11 18:03:33 -05:00
Antonio SJ Musumeci 0c6c69e02e update readme to include mergerfs.dedup 2016-03-11 18:03:22 -05:00
Antonio SJ Musumeci 4b6cfdc68a Merge pull request #258 from trapexit/tarball-url
change tar.gz build url
2016-03-11 16:55:26 -05:00
Antonio SJ Musumeci 309cfee52b change tar.gz build url 2016-03-11 16:55:10 -05:00
Antonio SJ Musumeci 9b3c085cf3 Merge pull request #257 from trapexit/man
tweak man page creation
2016-03-10 18:43:12 -05:00
Antonio SJ Musumeci 382ca876ca tweak man page creation 2016-03-10 18:42:32 -05:00
Antonio SJ Musumeci 93acfb015c Merge pull request #256 from trapexit/xattr
properly check errors of xattr. closes #255
2016-03-10 18:38:05 -05:00
Antonio SJ Musumeci 070ed08caa properly check errors of xattr. closes #255 2016-03-10 18:37:09 -05:00
Antonio SJ Musumeci 5d44161e77 Merge pull request #251 from trapexit/man
update precompiled man page
2016-03-06 02:23:47 -05:00
Antonio SJ Musumeci 6492fda483 update precompiled man page 2016-03-06 02:22:58 -05:00
Antonio SJ Musumeci 447fd8b2fb Merge pull request #250 from trapexit/rename
fix rename failing on non-path preserving policies
2016-03-06 02:22:23 -05:00
Antonio SJ Musumeci 2061211894 fix rename failing on non-path preserving policies 2016-03-06 02:21:23 -05:00
Antonio SJ Musumeci 5030d5a5b4 Merge pull request #249 from trapexit/clarify-rename
clarify that rename uses the create policy to make decisions
2016-03-04 20:33:10 -05:00
Antonio SJ Musumeci 4928944167 clarify that rename uses the create policy to make decisions 2016-03-04 20:32:52 -05:00
Antonio SJ Musumeci 6957cf39d1 Merge pull request #247 from trapexit/epmfs
re-add minfreespace check to epmfs policy
2016-03-04 13:56:15 -05:00
Antonio SJ Musumeci 12cf57dc5a re-add minfreespace check to epmfs policy 2016-03-04 13:52:31 -05:00
Antonio SJ Musumeci 26c2ebc843 Merge pull request #245 from trapexit/readme
change tooling names and add guide link
2016-03-03 10:47:45 -05:00
Antonio SJ Musumeci 59b08a5bc3 change tooling names and add guide link 2016-03-03 10:46:53 -05:00
70 changed files with 1714 additions and 467 deletions
+2
View File
@@ -1,4 +1,6 @@
/*
ISC License
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
+4 -6
View File
@@ -71,7 +71,7 @@ CFLAGS = -g -Wall \
$(OPTS) \
-Wno-unused-result \
$(FUSE_CFLAGS) \
-DFUSE_USE_VERSION=26 \
-DFUSE_USE_VERSION=29 \
-MMD \
-DFLAG_NOPATH=$(FLAG_NOPATH) \
-DFALLOCATE=$(FALLOCATE) \
@@ -134,7 +134,7 @@ obj/%.o: src/%.cpp
clean: rpm-clean
$(RM) -rf obj
$(RM) -f src/version.hpp
$(RM) -f "$(TARGET)" "$(MANPAGE)" mount.mergerfs
$(RM) -f "$(TARGET)" mount.mergerfs
$(FIND) . -name "*~" -delete
distclean: clean
@@ -150,7 +150,7 @@ install-mount.mergerfs: mount.mergerfs
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
install-man: $(MANPAGE)
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
$(INSTALL) -v -m 0644 -D "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
install-strip: install-base
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
@@ -168,9 +168,7 @@ uninstall-man:
$(MANPAGE): README.md
ifneq (,$(PANDOC))
$(PANDOC) -s -t man -o $(MANPAGE) README.md
else
$(CP) man/mergerfs.1 .
$(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
endif
man: $(MANPAGE)
+85 -49
View File
@@ -1,6 +1,6 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2016-02-21
% 2016-08-01
# NAME
@@ -12,7 +12,7 @@ mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
# DESCRIPTION
**mergerfs** is a union filesystem geared towards simplifing storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
**mergerfs** is a union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to **mhddfs**, **unionfs**, and **aufs**.
# FEATURES
@@ -24,7 +24,7 @@ mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
* Safe to run as root
* Opportunistic credential caching
* Works with heterogeneous filesystem types
* Handling of writes to full drives
* Handling of writes to full drives (transparently move file to drive with capacity)
* Handles pool of readonly and read/write drives
# OPTIONS
@@ -37,33 +37,38 @@ mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
* **moveonenospc**: when enabled (set to **true**) if a **write** fails with **ENOSPC** a scan of all drives will be done looking for the drive with most free space which is at least the size of the file plus the amount which failed to write. An attempt to move the file to that drive will occur (keeping all metadata possible) and if successful the original is unlinked and the write retried. (default: false)
* **func.&lt;func&gt;=&lt;policy&gt;**: sets the specific FUSE function's policy. See below for the list of value types. Example: **func.getattr=newest**
* **category.&lt;category&gt;=&lt;policy&gt;**: Sets policy of all FUSE functions in the provided category. Example: **category.create=mfs**
* **fsname**: sets the name of the filesystem as seen in **mount**, **df**, etc. Defaults to a list of the source paths concatenated together with the longest common prefix removed.
**NOTE:** Options are evaluated in the order listed so if the options are **func.rmdir=rand,category.action=ff** the **action** category setting will override the **rmdir** setting.
###srcmounts###
The source mounts argument is a colon (':') delimited list of paths. To make it simpler to include multiple source mounts without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will probably expand it.**
The srcmounts (source mounts) argument is a colon (':') delimited list of paths to be included in the pool. It does not matter if the paths are on the same or different drives nor does it matter the filesystem. Used and available space will not be duplicated for paths on the same device and any features which aren't supported by the underlying filesystem (such as file attributes or extended attributes) will return the appropriate errors.
To make it easier to include multiple source mounts mergerfs supports [globbing](http://linux.die.net/man/7/glob). **The globbing tokens MUST be escaped when using via the shell else the shell itself will expand it.**
```
$ mergerfs /mnt/disk\*:/mnt/cdrom /media/drives
$ mergerfs -o defaults,allow_other /mnt/disk\*:/mnt/cdrom /media/drives
```
The above line will use all mount points in /mnt prefixed with *disk* and the directory *cdrom*.
The above line will use all mount points in /mnt prefixed with **disk** and the **cdrom**.
In /etc/fstab it'd look like the following:
To have the pool mounted at boot or otherwise accessable from related tools use **/etc/fstab**.
```
# <file system> <mount point> <type> <options> <dump> <pass>
/mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs defaults,allow_other 0 0
```
**NOTE:** the globbing is done at mount or xattr update time. If a new directory is added matching the glob after the fact it will not be included.
**NOTE:** the globbing is done at mount or xattr update time (see below). If a new directory is added matching the glob after the fact it will not be automatically included.
**NOTE:** for mounting via **fstab** to work you must have **mount.fuse** installed. For Ubuntu/Debian it is included in the **fuse** package.
# FUNCTIONS / POLICIES / CATEGORIES
The filesystem has a number of functions. Those functions are grouped into 3 categories: **action**, **create**, **search**. These functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some are not very practical. For instance: **rand** (Random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod`.
The POSIX filesystem API has a number of functions. **creat**, **stat**, **chown**, etc. In mergerfs these functions are grouped into 3 categories: **action**, **create**, and **search**. Functions and categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a function or category though some are not very practical. For instance: **rand** (random) may be useful for file creation (create) but could lead to very odd behavior if used for `chmod` (though only if there were more than one copy of the file).
All policies when used to create will ignore drives which are mounted readonly. This allows for read/write and readonly drives to be mixed together.
Policies, when called to create, will ignore drives which are readonly or have less than **minfreespace**. This allows for read/write and readonly drives to be mixed together and keep drives which may remount as readonly on error from further affecting the pool.
#### Function / Category classifications ####
@@ -74,24 +79,29 @@ All policies when used to create will ignore drives which are mounted readonly.
| search | access, getattr, getxattr, ioctl, listxattr, open, readlink |
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release, statfs, write |
Due to FUSE limitations **ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) then **getattr** will be used.
Due to FUSE limitations **ioctl** behaves differently if its acting on a directory. It'll use the **getattr** policy to find and open the directory before issuing the **ioctl**. In other cases where something may be searched (to confirm a directory exists across all source mounts) **getattr** will also be used.
#### Policy descriptions ####
Most policies when called to create will filter out drives which are readonly or have less than **minfreespace**.
| Policy | Description |
|--------------|-------------|
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** perform on all read/write drives with **minfreespace**. **create** filters the same way but acts like **ff**. |
| eplfs (existing path, least free space) | If the path exists on multiple drives use the one with the least free space. Falls back to **lfs**. |
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space. Falls back to **mfs**. |
| all | Search category: acts like **ff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **ff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
| epall (existing path, all) | Search category: acts like **epff**. Action category: apply to all found. Create category: for **mkdir**, **mknod**, and **symlink** it will apply to all existing paths found. **create** works like **epff**. It will exclude readonly drives and those with free space less than **minfreespace**. |
| epff | Given the order of the drives, as defined at mount time or when configured via the xattr interface, act on the first one found where the path already exists. For **create** cateogry it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). Falls back to **ff**. |
| eplfs (existing path, least free space) | If the path exists on multiple drives use the one with the least free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lfs**. |
| eplus (existing path, least used space) | If the path exists on multiple drives the the one with the least used space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **lus**. |
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| eprand (existing path, random) | Calls **epall** and then randomizes. |
| erofs | Exclusively return **-1** with **errno** set to **EROFS**. By setting **create** functions to this you can in effect turn the filesystem readonly. |
| ff (first found) | Given the order of the drives, as defined at mount time or when configured via xattr interface, act on the first one found. |
| lfs (least free space) | Pick the drive with the least available free space but more than **minfreespace**. Falls back to **mfs**. |
| mfs (most free space) | Use the drive with the most available free space. Falls back to **ff**. |
| newest (newest file) | Pick the file / directory with the largest mtime. |
| ff (first found) | Given the order of the drives, as defined at mount time or when configured via xattr interface, act on the first one found. For **create** category it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
| lfs (least free space) | Pick the drive with the least available free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| lus (least used space) | Pick the drive with the least used space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **mfs**. |
| mfs (most free space) | Pick the drive with the most available free space. For **create** category it will exclude readonly drives and those with free space less than **minfreespace**. Falls back to **ff**. |
| newest (newest file) | Pick the file / directory with the largest mtime. For **create** category it will exclude readonly drives and those with free space less than **minfreespace** (unless there is no other option). |
| rand (random) | Calls **all** and then randomizes. |
**epff**, **eplfs**, **eplus**, and **epmf** are path preserving policies. As the descriptions above explain they will only consider drives where the path being accessed exists. Non-path preserving policies will clone paths as necessary.
#### Defaults ####
| Category | Policy |
@@ -102,14 +112,14 @@ Most policies when called to create will filter out drives which are readonly or
#### rename & link ####
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the source and destination paths existing on different mount points it will return `-1` with `errno = EXDEV`. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. This can lead to several undesirable situtations with or without errors and it's not entirely obvious what to do when an error occurs.
[rename](http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky function in a merged system. Normally if a rename can't be done atomically due to the source and destination paths existing on different mount points it will return **-1** with **errno = EXDEV**. The atomic rename is most critical for replacing files in place atomically (such as securing writing to a temp file and then replacing a target). The problem is that by merging multiple paths you can have N instances of the source and destinations on different drives. This can lead to several undesirable situtations with or without errors and it's not entirely obvious what to do when an error occurs.
Originally mergerfs would return EXDEV whenever a rename was requested which was cross directory in any way. This made the code simple and was technically complient with POSIX requirements. However, many applications fail to handle EXDEV at all and treat it as a normal error or they only partially support EXDEV (don't respond the same as `mv` would). Such apps include: gvfsd-fuse v1.20.3 and prior, Finder / CIFS/SMB client in Apple OSX 10.9+, NZBGet, Samba's recycling bin feature.
* If using a policy which tries to preserve directories (epmfs,eplfs)
* Using the `rename` policy get the list of files to rename
* If using a **create** policy which tries to preserve directory paths (epff,eplfs,eplus,epmfs)
* Using the **rename** policy get the list of files to rename
* For each file attempt rename:
* If failure with ENOENT run `create` policy
* If failure with ENOENT run **create** policy
* If create policy returns the same drive as currently evaluating then clone the path
* Re-attempt rename
* If **any** of the renames succeed the higher level rename is considered a success
@@ -117,9 +127,9 @@ Originally mergerfs would return EXDEV whenever a rename was requested which was
* On success:
* Remove the target from all drives with no source file
* Remove the source from all drives which failed to rename
* If using a policy which does **not** try to preserve directories
* Using the `rename` policy get the list of files to rename
* Using the `getattr` policy get the target path
* If using a **create** policy which does **not** try to preserve directory paths
* Using the **rename** policy get the list of files to rename
* Using the **getattr** policy get the target path
* For each file attempt rename:
* If the source drive != target drive:
* Clone target path from target drive to source drive
@@ -132,15 +142,13 @@ Originally mergerfs would return EXDEV whenever a rename was requested which was
The the removals are subject to normal entitlement checks.
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible. To remove the possibility all together mergerfs would need to perform the as `mv` does when it receives EXDEV normally.
The above behavior will help minimize the likelihood of EXDEV being returned but it will still be possible. To remove the possibility all together mergerfs would need to perform the as **mv** does when it receives EXDEV normally.
`link` uses the same basic strategy.
**link** uses the same basic strategy.
#### readdir ####
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple **first found** merging of directories and files found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from **getattr**.
It could be extended to offer the ability to see all files found. Perhaps concatenating **#** and a number to the name. But to really be useful you'd need to be able to access them which would complicate file lookup.
[readdir](http://linux.die.net/man/3/readdir) is different from all other filesystem functions. While it could have it's own set of policies to tweak its behavior at this time it provides a simple union of files and directories found. Remember that any action or information queried about these files and directories come from the respective function. For instance: an **ls** is a **readdir** and for each file/directory returned **getattr** is called. Meaning the policy of **getattr** is responsible for choosing the file/directory which is the source of the metadata you see in an **ls**.
#### statvfs ####
@@ -155,7 +163,7 @@ First get the code from [github](http://github.com/trapexit/mergerfs).
```
$ git clone https://github.com/trapexit/mergerfs.git
$ # or
$ wget https://github.com/trapexit/mergerfs/archive/master.zip
$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
```
#### Debian / Ubuntu
@@ -195,38 +203,40 @@ $ sudo make install
There is a pseudo file available at the mount point which allows for the runtime modification of certain **mergerfs** options. The file will not show up in **readdir** but can be **stat**'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
Even if xattrs are disabled for mergerfs the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls against this pseudo file will still work.
Any changes made at runtime are **not** persisted. If you wish for values to persist they must be included as options wherever you configure the mounting of mergerfs (fstab).
##### Keys #####
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
Use `xattr -l /mount/point/.mergerfs` to see all supported keys. Some are informational and therefore readonly.
##### user.mergerfs.srcmounts #####
###### user.mergerfs.srcmounts ######
For **user.mergerfs.srcmounts** there are several instructions available for manipulating the list. The value provided is just as the value used at mount time. A colon (':') delimited list of full path globs.
Used to query or modify the list of source mounts. When modifying there are several shortcuts to easy manipulation of the list.
| Instruction | Description |
| Value | Description |
|--------------|-------------|
| [list] | set |
| +<[list] | prepend |
| +>[list] | append |
| [list] | set |
| +<[list] | prepend |
| +>[list] | append |
| -[list] | remove all values provided |
| -< | remove first in list |
| -> | remove last in list |
##### minfreespace #####
###### minfreespace ######
Input: interger with an optional multiplier suffix. **K**, **M**, or **G**.
Output: value in bytes
##### moveonenospc #####
###### moveonenospc ######
Input: **true** and **false**
Ouput: **true** or **false**
##### categories / funcs #####
###### categories / funcs ######
Input: short policy string as described elsewhere in this document
@@ -261,7 +271,7 @@ newest
/tmp/a:/tmp/b:/tmp/c
```
#### mergerfs file xattrs ####
#### file / directory xattrs ####
While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) **mergerfs** offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
@@ -286,14 +296,17 @@ A B C
# TOOLING
Find tooling to help with managing `mergerfs` at: https://github.com/trapexit/mergerfs-tools
Find tooling to help with managing **mergerfs** at: https://github.com/trapexit/mergerfs-tools
* fsck.mergerfs: Provides permissions and ownership auditing and the ability to fix them
* mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
* mergerfs.dedup: Will help identify and optionally remove duplicate files
* mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible directories on a mergerfs mount
# TIPS / NOTES
* If you don't see some directories / files you expect in a merged point be sure the user has permission to all the underlying directories. If `/drive0/a` has is owned by `root:root` with ACLs set to `0700` and `/drive1/a` is `root:root` and `0755` you'll see only `/drive1/a`. Use `fsck.mergerfs` to audit the drive for out of sync permissions.
* https://github.com/trapexit/backup-and-recovery-howtos : A set of guides / howtos on creating a data storage system, backing it up, maintaining it, and recovering from failure.
* If you don't see some directories / files you expect in a merged point be sure the user has permission to all the underlying directories. If `/drive0/a` has is owned by `root:root` with ACLs set to `0700` and `/drive1/a` is `root:root` and `0755` you'll see only `/drive1/a`. Use `mergerfs.fsck` to audit the drive for out of sync permissions.
* Do *not* use `direct_io` if you expect applications (such as rtorrent) to [mmap](http://linux.die.net/man/2/mmap) files. It is not currently supported in FUSE w/ `direct_io` enabled.
* Since POSIX gives you only error or success on calls its difficult to determine the proper behavior when applying the behavior to multiple targets. **mergerfs** will return an error only if all attempts of an action fail. Any success will lead to a success returned.
* The recommended options are **defaults,allow_other**. The **allow_other** is to allow users who are not the one which executed mergerfs access to the mountpoint. **defaults** is described above and should offer the best performance. It's possible that if you're running on an older platform the **splice** features aren't available and could error. In that case simply use the other options manually.
* If write performance is valued more than read it may be useful to enable **direct_io**. Best to benchmark with and without and choose appropriately.
@@ -303,6 +316,14 @@ Find tooling to help with managing `mergerfs` at: https://github.com/trapexit/me
# KNOWN ISSUES / BUGS
#### rtorrent fails with ENODEV (No such device)
Be sure to turn off `direct_io`. rtorrent and some other applications use [mmap](http://linux.die.net/man/2/mmap) to read and write to files and offer no failback to traditional methods. FUSE does not currently support mmap while using `direct_io`. There will be a performance penalty on writes with `direct_io` off but it's the only way to get such applications to work. If the performance loss is too high for other apps you can mount mergerfs twice. Once with `direct_io` enabled and one without it.
#### mmap performance is really bad
There [is a bug](https://lkml.org/lkml/2016/3/16/260) in caching which affects overall performance of mmap through FUSE in Linux 4.x kernels. It is fixed in [4.4.10 and 4.5.4](https://lkml.org/lkml/2016/5/11/59).
#### Trashing files occasionally fails
This is the same issue as with Samba. `rename` returns `EXDEV` (in our case that will really only happen with path preserving policies like `epmfs`) and the software doesn't handle the situtation well. This is unfortunately a common failure of software which moves files around. The standard indicates that an implementation `MAY` choose to support non-user home directory trashing of files (which is a `MUST`). The implementation `MAY` also support "top directory trashes" which many probably do.
@@ -345,11 +366,20 @@ While aufs can offer better peak performance mergerfs offers more configurabilit
A single drive failure will lead to full pool failure without additional redundancy. mergerfs performs a similar behavior without the catastrophic failure and lack of recovery. Drives can fail and all other data will continue to be accessable.
#### Can drives be written to directly? Outside of mergerfs while pooled?
Yes. It will be represented immediately in the pool as the policies would describe.
#### Why do I get an "out of space" error even though the system says there's lots of space left?
Please reread the sections above about policies, path preserving, and the **moveonenospc** option. If the policy is path preserving and a drive is almost full and the drive the policy would pick then the writing of the file may fill the drive and receive ENOSPC errors. That is expected with those settings. If you don't want that: enable **moveonenospc** and don't use a path preserving policy.
#### It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
[mhddfs](https://github.com/trapexit/mhddfs) tries to handle being run as **root** by calling [getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319) and if it returns **0** then it will [chown](http://linux.die.net/man/1/chown) the file. Not only is that a race condition but it doesn't handle many other situations. Rather than attempting to simulate POSIX ACL behaviors the proper behavior is to use [seteuid](http://linux.die.net/man/2/seteuid) and [setegid](http://linux.die.net/man/2/setegid), become the user making the original call and perform the action as them. This is how [mergerfs](https://github.com/trapexit/mergerfs) handles things.
If you are familiar with POSIX standards you'll know that this behavior poses a problem. **seteuid** and **setegid** affect the whole process and **libfuse** is multithreaded by default. We'd need to lock access to **seteuid** and **setegid** with a mutex so that the several threads aren't stepping on one another and files end up with weird permissions and ownership. This however wouldn't scale well. With lots of calls the contention on that mutex would be extremely high. Thankfully on Linux and OSX we have a better solution.
If you are familiar with POSIX standards you'll know that this behavior poses a problem. **seteuid** and **setegid** affect the whole process and **libfuse** is multithreaded by default. We'd need to lock access to **seteuid** and **setegid** with a mutex so that the several threads aren't stepping on one anofther and files end up with weird permissions and ownership. This however wouldn't scale well. With lots of calls the contention on that mutex would be extremely high. Thankfully on Linux and OSX we have a better solution.
OSX has a [non-portable pthread extension](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) for per-thread user and group impersonation.
@@ -370,3 +400,9 @@ For non-Linux systems mergerfs uses a read-write lock and changes credentials on
#### Support development
* Gratipay: https://gratipay.com/~trapexit
* BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
# LINKS
* http://github.com/trapexit/mergerfs
* http://github.com/trapexit/mergerfs-tools
* http://github.com/trapexit/backup-and-recovery-howtos
+203 -68
View File
@@ -1,5 +1,5 @@
.\"t
.TH "mergerfs" "1" "2016\-02\-21" "mergerfs user manual" ""
.TH "mergerfs" "1" "2016\-08\-01" "mergerfs user manual" ""
.SH NAME
.PP
mergerfs \- another (FUSE based) union filesystem
@@ -8,7 +8,7 @@ mergerfs \- another (FUSE based) union filesystem
mergerfs \-o<options> <srcmounts> <mountpoint>
.SH DESCRIPTION
.PP
\f[B]mergerfs\f[] is a union filesystem geared towards simplifing
\f[B]mergerfs\f[] is a union filesystem geared towards simplifying
storage and management of files across numerous commodity storage
devices.
It is similar to \f[B]mhddfs\f[], \f[B]unionfs\f[], and \f[B]aufs\f[].
@@ -30,7 +30,8 @@ Opportunistic credential caching
.IP \[bu] 2
Works with heterogeneous filesystem types
.IP \[bu] 2
Handling of writes to full drives
Handling of writes to full drives (transparently move file to drive with
capacity)
.IP \[bu] 2
Handles pool of readonly and read/write drives
.SH OPTIONS
@@ -67,6 +68,11 @@ Example: \f[B]func.getattr=newest\f[]
\f[B]category.<category>=<policy>\f[]: Sets policy of all FUSE functions
in the provided category.
Example: \f[B]category.create=mfs\f[]
.IP \[bu] 2
\f[B]fsname\f[]: sets the name of the filesystem as seen in
\f[B]mount\f[], \f[B]df\f[], etc.
Defaults to a list of the source paths concatenated together with the
longest common prefix removed.
.PP
\f[B]NOTE:\f[] Options are evaluated in the order listed so if the
options are \f[B]func.rmdir=rand,category.action=ff\f[] the
@@ -74,24 +80,31 @@ options are \f[B]func.rmdir=rand,category.action=ff\f[] the
setting.
.SS srcmounts
.PP
The source mounts argument is a colon (\[aq]:\[aq]) delimited list of
paths.
To make it simpler to include multiple source mounts without having to
modify your fstab (http://linux.die.net/man/5/fstab) we also support
The srcmounts (source mounts) argument is a colon (\[aq]:\[aq])
delimited list of paths to be included in the pool.
It does not matter if the paths are on the same or different drives nor
does it matter the filesystem.
Used and available space will not be duplicated for paths on the same
device and any features which aren\[aq]t supported by the underlying
filesystem (such as file attributes or extended attributes) will return
the appropriate errors.
.PP
To make it easier to include multiple source mounts mergerfs supports
globbing (http://linux.die.net/man/7/glob).
\f[B]The globbing tokens MUST be escaped when using via the shell else
the shell itself will probably expand it.\f[]
the shell itself will expand it.\f[]
.IP
.nf
\f[C]
$\ mergerfs\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
$\ mergerfs\ \-o\ defaults,allow_other\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
\f[]
.fi
.PP
The above line will use all mount points in /mnt prefixed with
\f[I]disk\f[] and the directory \f[I]cdrom\f[].
\f[B]disk\f[] and the \f[B]cdrom\f[].
.PP
In /etc/fstab it\[aq]d look like the following:
To have the pool mounted at boot or otherwise accessable from related
tools use \f[B]/etc/fstab\f[].
.IP
.nf
\f[C]
@@ -100,24 +113,33 @@ In /etc/fstab it\[aq]d look like the following:
\f[]
.fi
.PP
\f[B]NOTE:\f[] the globbing is done at mount or xattr update time.
\f[B]NOTE:\f[] the globbing is done at mount or xattr update time (see
below).
If a new directory is added matching the glob after the fact it will not
be included.
be automatically included.
.PP
\f[B]NOTE:\f[] for mounting via \f[B]fstab\f[] to work you must have
\f[B]mount.fuse\f[] installed.
For Ubuntu/Debian it is included in the \f[B]fuse\f[] package.
.SH FUNCTIONS / POLICIES / CATEGORIES
.PP
The filesystem has a number of functions.
Those functions are grouped into 3 categories: \f[B]action\f[],
\f[B]create\f[], \f[B]search\f[].
These functions and categories can be assigned a policy which dictates
how \f[B]mergerfs\f[] behaves.
The POSIX filesystem API has a number of functions.
\f[B]creat\f[], \f[B]stat\f[], \f[B]chown\f[], etc.
In mergerfs these functions are grouped into 3 categories:
\f[B]action\f[], \f[B]create\f[], and \f[B]search\f[].
Functions and categories can be assigned a policy which dictates how
\f[B]mergerfs\f[] behaves.
Any policy can be assigned to a function or category though some are not
very practical.
For instance: \f[B]rand\f[] (Random) may be useful for file creation
(create) but could lead to very odd behavior if used for \f[C]chmod\f[].
For instance: \f[B]rand\f[] (random) may be useful for file creation
(create) but could lead to very odd behavior if used for \f[C]chmod\f[]
(though only if there were more than one copy of the file).
.PP
All policies when used to create will ignore drives which are mounted
readonly.
This allows for read/write and readonly drives to be mixed together.
Policies, when called to create, will ignore drives which are readonly
or have less than \f[B]minfreespace\f[].
This allows for read/write and readonly drives to be mixed together and
keep drives which may remount as readonly on error from further
affecting the pool.
.SS Function / Category classifications
.PP
.TS
@@ -158,12 +180,9 @@ on a directory.
It\[aq]ll use the \f[B]getattr\f[] policy to find and open the directory
before issuing the \f[B]ioctl\f[].
In other cases where something may be searched (to confirm a directory
exists across all source mounts) then \f[B]getattr\f[] will be used.
exists across all source mounts) \f[B]getattr\f[] will also be used.
.SS Policy descriptions
.PP
Most policies when called to create will filter out drives which are
readonly or have less than \f[B]minfreespace\f[].
.PP
.TS
tab(@);
l l.
@@ -179,25 +198,66 @@ T}@T{
Search category: acts like \f[B]ff\f[].
Action category: apply to all found.
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
\f[B]symlink\f[] perform on all read/write drives with
\f[B]symlink\f[] it will apply to all found.
\f[B]create\f[] works like \f[B]ff\f[].
It will exclude readonly drives and those with free space less than
\f[B]minfreespace\f[].
\f[B]create\f[] filters the same way but acts like \f[B]ff\f[].
T}
T{
epall (existing path, all)
T}@T{
Search category: acts like \f[B]epff\f[].
Action category: apply to all found.
Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
\f[B]symlink\f[] it will apply to all existing paths found.
\f[B]create\f[] works like \f[B]epff\f[].
It will exclude readonly drives and those with free space less than
\f[B]minfreespace\f[].
T}
T{
epff
T}@T{
Given the order of the drives, as defined at mount time or when
configured via the xattr interface, act on the first one found where the
path already exists.
For \f[B]create\f[] cateogry it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[] (unless there is no
other option).
Falls back to \f[B]ff\f[].
T}
T{
eplfs (existing path, least free space)
T}@T{
If the path exists on multiple drives use the one with the least free
space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]lfs\f[].
T}
T{
eplus (existing path, least used space)
T}@T{
If the path exists on multiple drives the the one with the least used
space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]lus\f[].
T}
T{
epmfs (existing path, most free space)
T}@T{
If the path exists on multiple drives use the one with the most free
space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]mfs\f[].
T}
T{
eprand (existing path, random)
T}@T{
Calls \f[B]epall\f[] and then randomizes.
T}
T{
erofs
T}@T{
Exclusively return \f[B]\-1\f[] with \f[B]errno\f[] set to
@@ -210,24 +270,41 @@ ff (first found)
T}@T{
Given the order of the drives, as defined at mount time or when
configured via xattr interface, act on the first one found.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[] (unless there is no
other option).
T}
T{
lfs (least free space)
T}@T{
Pick the drive with the least available free space but more than
\f[B]minfreespace\f[].
Pick the drive with the least available free space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]mfs\f[].
T}
T{
lus (least used space)
T}@T{
Pick the drive with the least used space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]mfs\f[].
T}
T{
mfs (most free space)
T}@T{
Use the drive with the most available free space.
Pick the drive with the most available free space.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[].
Falls back to \f[B]ff\f[].
T}
T{
newest (newest file)
T}@T{
Pick the file / directory with the largest mtime.
For \f[B]create\f[] category it will exclude readonly drives and those
with free space less than \f[B]minfreespace\f[] (unless there is no
other option).
T}
T{
rand (random)
@@ -235,6 +312,12 @@ T}@T{
Calls \f[B]all\f[] and then randomizes.
T}
.TE
.PP
\f[B]epff\f[], \f[B]eplfs\f[], \f[B]eplus\f[], and \f[B]epmf\f[] are
path preserving policies.
As the descriptions above explain they will only consider drives where
the path being accessed exists.
Non\-path preserving policies will clone paths as necessary.
.SS Defaults
.PP
.TS
@@ -268,7 +351,7 @@ rename (http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky
function in a merged system.
Normally if a rename can\[aq]t be done atomically due to the source and
destination paths existing on different mount points it will return
\f[C]\-1\f[] with \f[C]errno\ =\ EXDEV\f[].
\f[B]\-1\f[] with \f[B]errno = EXDEV\f[].
The atomic rename is most critical for replacing files in place
atomically (such as securing writing to a temp file and then replacing a
target).
@@ -287,14 +370,15 @@ same as \f[C]mv\f[] would).
Such apps include: gvfsd\-fuse v1.20.3 and prior, Finder / CIFS/SMB
client in Apple OSX 10.9+, NZBGet, Samba\[aq]s recycling bin feature.
.IP \[bu] 2
If using a policy which tries to preserve directories (epmfs,eplfs)
If using a \f[B]create\f[] policy which tries to preserve directory
paths (epff,eplfs,eplus,epmfs)
.IP \[bu] 2
Using the \f[C]rename\f[] policy get the list of files to rename
Using the \f[B]rename\f[] policy get the list of files to rename
.IP \[bu] 2
For each file attempt rename:
.RS 2
.IP \[bu] 2
If failure with ENOENT run \f[C]create\f[] policy
If failure with ENOENT run \f[B]create\f[] policy
.IP \[bu] 2
If create policy returns the same drive as currently evaluating then
clone the path
@@ -316,11 +400,12 @@ Remove the target from all drives with no source file
Remove the source from all drives which failed to rename
.RE
.IP \[bu] 2
If using a policy which does \f[B]not\f[] try to preserve directories
If using a \f[B]create\f[] policy which does \f[B]not\f[] try to
preserve directory paths
.IP \[bu] 2
Using the \f[C]rename\f[] policy get the list of files to rename
Using the \f[B]rename\f[] policy get the list of files to rename
.IP \[bu] 2
Using the \f[C]getattr\f[] policy get the target path
Using the \f[B]getattr\f[] policy get the target path
.IP \[bu] 2
For each file attempt rename:
.RS 2
@@ -351,26 +436,22 @@ The the removals are subject to normal entitlement checks.
The above behavior will help minimize the likelihood of EXDEV being
returned but it will still be possible.
To remove the possibility all together mergerfs would need to perform
the as \f[C]mv\f[] does when it receives EXDEV normally.
the as \f[B]mv\f[] does when it receives EXDEV normally.
.PP
\f[C]link\f[] uses the same basic strategy.
\f[B]link\f[] uses the same basic strategy.
.SS readdir
.PP
readdir (http://linux.die.net/man/3/readdir) is different from all other
filesystem functions.
It certainly could have it\[aq]s own set of policies to tweak its
behavior.
At this time it provides a simple \f[B]first found\f[] merging of
directories and files found.
That is: only the first file or directory found for a directory is
returned.
Given how FUSE works though the data representing the returned entry
comes from \f[B]getattr\f[].
.PP
It could be extended to offer the ability to see all files found.
Perhaps concatenating \f[B]#\f[] and a number to the name.
But to really be useful you\[aq]d need to be able to access them which
would complicate file lookup.
While it could have it\[aq]s own set of policies to tweak its behavior
at this time it provides a simple union of files and directories found.
Remember that any action or information queried about these files and
directories come from the respective function.
For instance: an \f[B]ls\f[] is a \f[B]readdir\f[] and for each
file/directory returned \f[B]getattr\f[] is called.
Meaning the policy of \f[B]getattr\f[] is responsible for choosing the
file/directory which is the source of the metadata you see in an
\f[B]ls\f[].
.SS statvfs
.PP
statvfs (http://linux.die.net/man/2/statvfs) normalizes the source
@@ -391,7 +472,7 @@ First get the code from github (http://github.com/trapexit/mergerfs).
\f[C]
$\ git\ clone\ https://github.com/trapexit/mergerfs.git
$\ #\ or
$\ wget\ https://github.com/trapexit/mergerfs/archive/master.zip
$\ wget\ https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs\-<ver>.tar.gz
\f[]
.fi
.SS Debian / Ubuntu
@@ -442,25 +523,29 @@ The file will not show up in \f[B]readdir\f[] but can be
\f[B]stat\f[]\[aq]ed and manipulated via
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
.PP
Even if xattrs are disabled the
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls will
still work.
Even if xattrs are disabled for mergerfs the
{list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls
against this pseudo file will still work.
.PP
Any changes made at runtime are \f[B]not\f[] persisted.
If you wish for values to persist they must be included as options
wherever you configure the mounting of mergerfs (fstab).
.SS Keys
.PP
Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
keys.
Some are informational and therefore readonly.
.SS user.mergerfs.srcmounts
.PP
For \f[B]user.mergerfs.srcmounts\f[] there are several instructions
available for manipulating the list.
The value provided is just as the value used at mount time.
A colon (\[aq]:\[aq]) delimited list of full path globs.
Used to query or modify the list of source mounts.
When modifying there are several shortcuts to easy manipulation of the
list.
.PP
.TS
tab(@);
l l.
T{
Instruction
Value
T}@T{
Description
T}
@@ -544,7 +629,7 @@ newest
/tmp/a:/tmp/b:/tmp/c
\f[]
.fi
.SS mergerfs file xattrs
.SS file / directory xattrs
.PP
While they won\[aq]t show up when using
listxattr (http://linux.die.net/man/2/listxattr) \f[B]mergerfs\f[]
@@ -582,24 +667,34 @@ A\ B\ C
.fi
.SH TOOLING
.PP
Find tooling to help with managing \f[C]mergerfs\f[] at:
Find tooling to help with managing \f[B]mergerfs\f[] at:
https://github.com/trapexit/mergerfs\-tools
.IP \[bu] 2
fsck.mergerfs: Provides permissions and ownership auditing and the
mergerfs.fsck: Provides permissions and ownership auditing and the
ability to fix them
.IP \[bu] 2
mergerfs.dedup: Will help identify and optionally remove duplicate files
.IP \[bu] 2
mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible
directories on a mergerfs mount
.SH TIPS / NOTES
.IP \[bu] 2
https://github.com/trapexit/backup\-and\-recovery\-howtos : A set of
guides / howtos on creating a data storage system, backing it up,
maintaining it, and recovering from failure.
.IP \[bu] 2
If you don\[aq]t see some directories / files you expect in a merged
point be sure the user has permission to all the underlying directories.
If \f[C]/drive0/a\f[] has is owned by \f[C]root:root\f[] with ACLs set
to \f[C]0700\f[] and \f[C]/drive1/a\f[] is \f[C]root:root\f[] and
\f[C]0755\f[] you\[aq]ll see only \f[C]/drive1/a\f[].
Use \f[C]fsck.mergerfs\f[] to audit the drive for out of sync
Use \f[C]mergerfs.fsck\f[] to audit the drive for out of sync
permissions.
.IP \[bu] 2
Do \f[I]not\f[] use \f[C]direct_io\f[] if you expect applications (such
as rtorrent) to mmap (http://linux.die.net/man/2/mmap) files.
It is not currently supported in FUSE w/ \f[C]direct_io\f[] enabled.
.IP \[bu] 2
Since POSIX gives you only error or success on calls its difficult to
determine the proper behavior when applying the behavior to multiple
targets.
@@ -648,6 +743,23 @@ Due to previously mentioned issues its generally best to set
This will help limit the confusion of tools such as
rsync (http://linux.die.net/man/1/rsync).
.SH KNOWN ISSUES / BUGS
.SS rtorrent fails with ENODEV (No such device)
.PP
Be sure to turn off \f[C]direct_io\f[].
rtorrent and some other applications use
mmap (http://linux.die.net/man/2/mmap) to read and write to files and
offer no failback to traditional methods.
FUSE does not currently support mmap while using \f[C]direct_io\f[].
There will be a performance penalty on writes with \f[C]direct_io\f[]
off but it\[aq]s the only way to get such applications to work.
If the performance loss is too high for other apps you can mount
mergerfs twice.
Once with \f[C]direct_io\f[] enabled and one without it.
.SS mmap performance is really bad
.PP
There is a bug (https://lkml.org/lkml/2016/3/16/260) in caching which
affects overall performance of mmap through FUSE in Linux 4.x kernels.
It is fixed in 4.4.10 and 4.5.4 (https://lkml.org/lkml/2016/5/11/59).
.SS Trashing files occasionally fails
.PP
This is the same issue as with Samba.
@@ -767,6 +879,22 @@ redundancy.
mergerfs performs a similar behavior without the catastrophic failure
and lack of recovery.
Drives can fail and all other data will continue to be accessable.
.SS Can drives be written to directly? Outside of mergerfs while pooled?
.PP
Yes.
It will be represented immediately in the pool as the policies would
describe.
.SS Why do I get an "out of space" error even though the system says
there\[aq]s lots of space left?
.PP
Please reread the sections above about policies, path preserving, and
the \f[B]moveonenospc\f[] option.
If the policy is path preserving and a drive is almost full and the
drive the policy would pick then the writing of the file may fill the
drive and receive ENOSPC errors.
That is expected with those settings.
If you don\[aq]t want that: enable \f[B]moveonenospc\f[] and don\[aq]t
use a path preserving policy.
.SS It\[aq]s mentioned that there are some security issues with mhddfs.
What are they? How does mergerfs address them?
.PP
@@ -790,7 +918,7 @@ behavior poses a problem.
\f[B]libfuse\f[] is multithreaded by default.
We\[aq]d need to lock access to \f[B]seteuid\f[] and \f[B]setegid\f[]
with a mutex so that the several threads aren\[aq]t stepping on one
another and files end up with weird permissions and ownership.
anofther and files end up with weird permissions and ownership.
This however wouldn\[aq]t scale well.
With lots of calls the contention on that mutex would be extremely high.
Thankfully on Linux and OSX we have a better solution.
@@ -853,5 +981,12 @@ email: trapexit\@spawn.link
Gratipay: https://gratipay.com/~trapexit
.IP \[bu] 2
BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
.SH LINKS
.IP \[bu] 2
http://github.com/trapexit/mergerfs
.IP \[bu] 2
http://github.com/trapexit/mergerfs\-tools
.IP \[bu] 2
http://github.com/trapexit/backup\-and\-recovery\-howtos
.SH AUTHORS
Antonio SJ Musumeci <trapexit@spawn.link>.
+4 -3
View File
@@ -17,8 +17,9 @@
#include <string>
#include <vector>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "config.hpp"
#include "fs_path.hpp"
@@ -34,7 +35,7 @@ static
int
_access(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int mask)
{
@@ -48,7 +49,7 @@ _access(Policy::Func::Search searchFunc,
fs::path::make(basepaths[0],fusepath,fullpath);
rv = ::eaccess(fullpath.c_str(),mask);
rv = ::faccessat(AT_FDCWD,fullpath.c_str(),mask,AT_EACCESS);
return ((rv == -1) ? -errno : 0);
}
+1 -1
View File
@@ -68,7 +68,7 @@ static
int
_chmod(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
{
+1 -1
View File
@@ -72,7 +72,7 @@ static
int
_chown(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const uid_t uid,
const gid_t gid)
+1 -1
View File
@@ -45,7 +45,7 @@ namespace mergerfs
std::string destmount;
std::vector<std::string> srcmounts;
mutable pthread_rwlock_t srcmountslock;
size_t minfreespace;
uint64_t minfreespace;
bool moveonenospc;
public:
+1 -1
View File
@@ -71,7 +71,7 @@ int
_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const int flags,
+3 -17
View File
@@ -19,8 +19,8 @@
#include <fuse.h>
#include <errno.h>
#include <fcntl.h>
#include "fs_fallocate.hpp"
#include "fileinfo.hpp"
static
@@ -32,22 +32,7 @@ _fallocate(const int fd,
{
int rv;
#ifdef _GNU_SOURCE
rv = ::fallocate(fd,mode,offset,len);
#elif defined _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
if(mode)
{
rv = -1;
errno = EOPNOTSUPP;
}
else
{
rv = ::posix_fallocate(fd,offset,len);
}
#else
rv = -1;
errno = EOPNOTSUPP;
#endif
rv = fs::fallocate(fd,mode,offset,len);
return ((rv == -1) ? -errno : 0);
}
@@ -65,6 +50,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _fallocate(fi->fd,
mode,
offset,
+25 -7
View File
@@ -22,6 +22,7 @@
#include <fcntl.h>
#include <glob.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
@@ -73,7 +74,8 @@ namespace fs
bool
info(const string &path,
bool &readonly,
size_t &spaceavail)
uint64_t &spaceavail,
uint64_t &spaceused)
{
bool rv;
struct statvfs st;
@@ -83,6 +85,7 @@ namespace fs
{
readonly = StatVFS::readonly(st);
spaceavail = StatVFS::spaceavail(st);
spaceused = StatVFS::spaceused(st);
}
return rv;
@@ -101,7 +104,7 @@ namespace fs
bool
spaceavail(const string &path,
size_t &spaceavail)
uint64_t &spaceavail)
{
bool rv;
struct statvfs st;
@@ -113,6 +116,20 @@ namespace fs
return rv;
}
bool
spaceused(const string &path,
uint64_t &spaceused)
{
bool rv;
struct statvfs st;
rv = fs::statvfs(path,st);
if(rv)
spaceused = StatVFS::spaceused(st);
return rv;
}
void
findallfiles(const vector<string> &srcmounts,
const char *fusepath,
@@ -195,15 +212,16 @@ namespace fs
realpathize(vector<string> &strs)
{
char *rv;
char buf[PATH_MAX];
for(size_t i = 0; i < strs.size(); i++)
{
rv = ::realpath(strs[i].c_str(),buf);
rv = ::realpath(strs[i].c_str(),NULL);
if(rv == NULL)
continue;
strs[i] = buf;
strs[i] = rv;
::free(rv);
}
}
@@ -215,7 +233,7 @@ namespace fs
int
mfs(const vector<string> &basepaths,
const size_t minfreespace,
const uint64_t minfreespace,
string &path)
{
fsblkcnt_t mfs;
@@ -225,7 +243,7 @@ namespace fs
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string &basepath = basepaths[i];
if(!fs::spaceavail(basepath,spaceavail))
+9 -4
View File
@@ -17,12 +17,13 @@
#ifndef __FS_HPP__
#define __FS_HPP__
#include <stdint.h>
#include <string>
#include <vector>
namespace fs
{
using std::size_t;
using std::string;
using std::vector;
@@ -35,12 +36,16 @@ namespace fs
bool info(const string &path,
bool &readonly,
size_t &spaceavail);
uint64_t &spaceavail,
uint64_t &spaceused);
bool readonly(const string &path);
bool spaceavail(const string &path,
size_t &spaceavail);
uint64_t &spaceavail);
bool spaceused(const string &path,
uint64_t &spaceavail);
void findallfiles(const vector<string> &srcmounts,
const char *fusepath,
@@ -59,7 +64,7 @@ namespace fs
int getfl(const int fd);
int mfs(const vector<string> &srcs,
const size_t minfreespace,
const uint64_t minfreespace,
string &path);
};
+5 -111
View File
@@ -14,114 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
using std::string;
namespace fs
{
namespace attr
{
static
int
get_fs_ioc_flags(const int fd,
int &flags)
{
return ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
}
static
int
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = get_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
static
int
set_fs_ioc_flags(const int fd,
const int flags)
{
return ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = set_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
int
copy(const int fdin,
const int fdout)
{
int rv;
int flags;
rv = get_fs_ioc_flags(fdin,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(fdout,flags);
}
int
copy(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
}
}
#ifdef __linux__
# include "fs_attr_linux.icpp"
#else
# include "fs_attr_unsupported.icpp"
#endif
+127
View File
@@ -0,0 +1,127 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
using std::string;
namespace fs
{
namespace attr
{
static
int
get_fs_ioc_flags(const int fd,
int &flags)
{
return ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
}
static
int
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = get_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
static
int
set_fs_ioc_flags(const int fd,
const int flags)
{
return ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = set_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
int
copy(const int fdin,
const int fdout)
{
int rv;
int flags;
rv = get_fs_ioc_flags(fdin,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(fdout,flags);
}
int
copy(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
}
}
+37
View File
@@ -0,0 +1,37 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
namespace fs
{
namespace attr
{
int
copy(const int fdin,
const int fdout)
{
return ENOTSUP;
}
int
copy(const string &from,
const string &to)
{
return ENOTSUP;
}
}
}
+14 -30
View File
@@ -14,20 +14,20 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#ifdef __linux__
#include <sys/sendfile.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "fs_attr.hpp"
#include "fs_fallocate.hpp"
#include "fs_sendfile.hpp"
#include "fs_time.hpp"
#include "fs_xattr.hpp"
using std::string;
@@ -35,20 +35,6 @@ using std::vector;
namespace fs
{
static
ssize_t
sendfile(const int fdin,
const int fdout,
const size_t count)
{
#if defined __linux__
off_t offset = 0;
return ::sendfile(fdout,fdin,&offset,count);
#else
return (errno=EINVAL,-1);
#endif
}
int
writen(const int fd,
const char *buf,
@@ -69,7 +55,7 @@ namespace fs
}
nleft -= nwritten;
buf += nwritten;
buf += nwritten;
}
return count;
@@ -91,6 +77,8 @@ namespace fs
bufsize = (blocksize * 16);
buf.resize(bufsize);
::lseek(fdin,0,SEEK_SET);
totalwritten = 0;
while(totalwritten < count)
{
@@ -99,8 +87,7 @@ namespace fs
{
if(errno == EINTR)
continue;
else
return -1;
return -1;
}
nw = writen(fdout,&buf[0],nr);
@@ -125,7 +112,7 @@ namespace fs
::posix_fadvise(fdin,0,count,POSIX_FADV_WILLNEED);
::posix_fadvise(fdin,0,count,POSIX_FADV_SEQUENTIAL);
::posix_fallocate(fdout,0,count);
fs::fallocate(fdout,0,0,count);
rv = fs::sendfile(fdin,fdout,count);
if((rv == -1) && ((errno == EINVAL) || (errno == ENOSYS)))
@@ -182,10 +169,7 @@ namespace fs
if(rv == -1)
return -1;
struct timespec times[2];
times[0] = stin.st_atim;
times[1] = stin.st_mtim;
rv = ::futimens(fdout,times);
rv = fs::utimes(fdout,stin);
if(rv == -1)
return -1;
+25
View File
@@ -0,0 +1,25 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __linux__
# include "fs_fallocate_linux.icpp"
#elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
# include "fs_fallocate_posix.icpp"
#elif __APPLE__
# include "fs_fallocate_osx.icpp"
#else
# include "fs_fallocate_unsupported.icpp"
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __FS_FALLOCATE_HPP__
#define __FS_FALLOCATE_HPP__
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len);
}
#endif // __FS_FALLOCATE_HPP__
+32
View File
@@ -0,0 +1,32 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include "fs_fallocate.hpp"
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
return ::fallocate(fd,mode,offset,len);
}
}
+57
View File
@@ -0,0 +1,57 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include "fs_fallocate.hpp"
namespace fs
{
static
int
_fallocate_core(const int fd,
const off_t offset,
const off_t len)
{
int rv;
fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0};
rv = ::fcntl(fd,F_PREALLOCATE,&store);
if(rv == -1)
{
store.fst_flags = F_ALLOCATEALL;
rv = ::fcntl(fd,F_PREALLOCATE,&store);
}
if(rv == -1)
return rv;
return ::ftruncate(fd,(offset+len));
}
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
if(mode)
return (errno=EOPNOTSUPP,-1);
return ::_fallocate_core(fd,offset,len);
}
}
+34
View File
@@ -0,0 +1,34 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <fcntl.h>
#include "fs_fallocate.hpp"
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
return (mode ?
(errno=EOPNOTSUPP,-1) :
(::posix_fallocate(fd,offset,len)));
}
}
+31
View File
@@ -0,0 +1,31 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include "fs_fallocate.hpp"
namespace fs
{
int
fallocate(const int fd,
const int mode,
const off_t offset,
const off_t len)
{
return (errno=EOPNOTSUPP,-1);
}
}
+21
View File
@@ -0,0 +1,21 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __linux__
# include "fs_sendfile_linux.icpp"
#else
# include "fs_sendfile_unsupported.icpp"
#endif
+28
View File
@@ -0,0 +1,28 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __FS_SENDFILE_HPP__
#define __FS_SENDFILE_HPP__
namespace fs
{
ssize_t
sendfile(const int fdin,
const int fdout,
const size_t count);
}
#endif // __FS_SENDFILE_HPP__
+31
View File
@@ -0,0 +1,31 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <sys/sendfile.h>
namespace fs
{
ssize_t
sendfile(const int fdin,
const int fdout,
const size_t count)
{
off_t offset = 0;
return ::sendfile(fdout,fdin,&offset,count);
}
}
+28
View File
@@ -0,0 +1,28 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
namespace fs
{
ssize_t
sendfile(const int fdin,
const int fdout,
const size_t count)
{
return (errno=EINVAL,-1);
}
}
+21
View File
@@ -0,0 +1,21 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __linux__
# include "fs_time_futimens.icpp"
#else
# include "fs_time_futimes.icpp"
#endif
+22
View File
@@ -0,0 +1,22 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
namespace fs
{
int
utimes(const int fd,
const struct stat &st);
}
+33
View File
@@ -0,0 +1,33 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <fcntl.h>
#include <sys/stat.h>
namespace fs
{
int
utimes(const int fd,
const struct stat &st)
{
struct timespec times[2];
times[0] = st.st_atim;
times[1] = st.st_mtim;
return ::futimens(fd,times);
}
}
+33
View File
@@ -0,0 +1,33 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/stat.h>
#include <sys/time.h>
namespace fs
{
int
utimes(const int fd,
const struct stat &st)
{
struct timeval times[2];
TIMESPEC_TO_TIMEVAL(&times[0],&st.st_atimespec);
TIMESPEC_TO_TIMEVAL(&times[1],&st.st_mtimespec);
return ::futimes(fd,times);
}
}
+47 -49
View File
@@ -44,23 +44,23 @@ namespace fs
{
#ifndef WITHOUT_XATTR
ssize_t rv;
ssize_t size;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
while((rv == -1) && (errno == ERANGE))
{
size = ::flistxattr(fd,NULL,0);
attrs.resize(size);
if(size == 0)
return 0;
rv = ::flistxattr(fd,&attrs[0],size);
rv = ::flistxattr(fd,NULL,0);
if(rv <= 0)
return rv;
attrs.resize(rv);
rv = ::flistxattr(fd,&attrs[0],rv);
}
return rv;
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
@@ -69,24 +69,24 @@ namespace fs
vector<char> &attrs)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
ssize_t rv;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
while((rv == -1) && (errno == ERANGE))
{
size = ::listxattr(path.c_str(),NULL,0);
attrs.resize(size);
if(size == 0)
return 0;
rv = ::listxattr(path.c_str(),&attrs[0],size);
rv = ::llistxattr(path.c_str(),NULL,0);
if(rv <= 0)
return rv;
attrs.resize(rv);
rv = ::llistxattr(path.c_str(),&attrs[0],rv);
}
return rv;
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
@@ -126,7 +126,7 @@ namespace fs
int
list(const int fd,
string &attrstr)
string &attrstr)
{
int rv;
vector<char> attrs;
@@ -158,24 +158,24 @@ namespace fs
vector<char> &value)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
ssize_t rv;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
while((rv == -1) && (errno == ERANGE))
{
size = ::fgetxattr(fd,attr.c_str(),NULL,0);
value.resize(size);
if(size == 0)
return 0;
rv = ::fgetxattr(fd,attr.c_str(),&value[0],size);
rv = ::fgetxattr(fd,attr.c_str(),NULL,0);
if(rv <= 0)
return rv;
value.resize(rv);
rv = ::fgetxattr(fd,attr.c_str(),&value[0],rv);
}
return rv;
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
@@ -185,24 +185,24 @@ namespace fs
vector<char> &value)
{
#ifndef WITHOUT_XATTR
int rv;
int size;
ssize_t rv;
rv = -1;
errno = ERANGE;
while(rv == -1 && errno == ERANGE)
while((rv == -1) && (errno == ERANGE))
{
size = ::getxattr(path.c_str(),attr.c_str(),NULL,0);
value.resize(size);
if(size == 0)
return 0;
rv = ::getxattr(path.c_str(),attr.c_str(),&value[0],size);
rv = ::lgetxattr(path.c_str(),attr.c_str(),NULL,0);
if(rv <= 0)
return rv;
value.resize(rv);
rv = ::lgetxattr(path.c_str(),attr.c_str(),&value[0],rv);
}
return rv;
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
@@ -305,8 +305,7 @@ namespace fs
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
@@ -317,14 +316,13 @@ namespace fs
const int flags)
{
#ifndef WITHOUT_XATTR
return ::setxattr(path.c_str(),
key.c_str(),
value.data(),
value.size(),
flags);
return ::lsetxattr(path.c_str(),
key.c_str(),
value.data(),
value.size(),
flags);
#else
errno = ENOTSUP;
return -1;
return (errno=ENOTSUP,-1);
#endif
}
-1
View File
@@ -25,7 +25,6 @@ namespace fs
{
namespace xattr
{
using std::size_t;
using std::string;
using std::vector;
using std::map;
+1 -1
View File
@@ -62,7 +62,7 @@ static
int
_getattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
struct stat &buf)
{
+5 -7
View File
@@ -20,8 +20,10 @@
#include <vector>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "config.hpp"
#include "fileinfo.hpp"
@@ -48,10 +50,6 @@ _ioctl(const int fd,
#ifdef FUSE_IOCTL_DIR
#ifndef O_DIRECTORY
#define O_DIRECTORY 0
#endif
#ifndef O_NOATIME
#define O_NOATIME 0
#endif
@@ -60,7 +58,7 @@ static
int
_ioctl_dir_base(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int cmd,
void *data)
@@ -76,7 +74,7 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
fs::path::make(basepaths[0],fusepath,fullpath);
const int flags = O_RDWR | O_NOATIME | O_DIRECTORY;
const int flags = O_RDONLY | O_NOATIME | O_NONBLOCK;
fd = ::open(fullpath.c_str(),flags);
if(fd == -1)
return -errno;
+7 -7
View File
@@ -88,7 +88,7 @@ int
_link_create_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
@@ -117,7 +117,7 @@ int
_clonepath_if_would_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath)
@@ -158,7 +158,7 @@ int
_link_preserve_path_core(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath,
@@ -190,7 +190,7 @@ int
_link_preserve_path_loop(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath,
const vector<const string*> &oldbasepaths)
@@ -216,9 +216,9 @@ _link_preserve_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
int rv;
vector<const string*> oldbasepaths;
+1 -1
View File
@@ -74,7 +74,7 @@ static
int
_listxattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
char *list,
const size_t size)
+1 -1
View File
@@ -85,7 +85,7 @@ int
_mkdir(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
{
+1 -1
View File
@@ -89,7 +89,7 @@ int
_mknod(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const dev_t dev)
+5 -4
View File
@@ -14,6 +14,7 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string>
@@ -21,11 +22,11 @@
namespace num
{
int
to_size_t(const std::string &str,
size_t &value)
to_uint64_t(const std::string &str,
uint64_t &value)
{
size_t tmp;
char *endptr;
char *endptr;
uint64_t tmp;
tmp = strtoll(str.c_str(),&endptr,10);
switch(*endptr)
+3 -1
View File
@@ -14,9 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <string>
namespace num
{
int to_size_t(const std::string &str, size_t &value);
int to_uint64_t(const std::string &str, uint64_t &value);
}
+1 -1
View File
@@ -58,7 +58,7 @@ static
int
_open(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int flags,
uint64_t &fh)
+2 -2
View File
@@ -107,11 +107,11 @@ set_default_options(fuse_args &args)
static
int
parse_and_process_minfreespace(const std::string &value,
size_t &minfreespace)
uint64_t &minfreespace)
{
int rv;
rv = num::to_size_t(value,minfreespace);
rv = num::to_uint64_t(value,minfreespace);
if(rv == -1)
return 1;
+10
View File
@@ -30,11 +30,16 @@ namespace mergerfs
buildvector<Policy,true>
(POLICY(invalid,DOESNT_PRESERVE_PATH))
(POLICY(all,DOESNT_PRESERVE_PATH))
(POLICY(epall,PRESERVES_PATH))
(POLICY(epff,PRESERVES_PATH))
(POLICY(eplfs,PRESERVES_PATH))
(POLICY(eplus,PRESERVES_PATH))
(POLICY(epmfs,PRESERVES_PATH))
(POLICY(eprand,PRESERVES_PATH))
(POLICY(erofs,DOESNT_PRESERVE_PATH))
(POLICY(ff,DOESNT_PRESERVE_PATH))
(POLICY(lfs,DOESNT_PRESERVE_PATH))
(POLICY(lus,DOESNT_PRESERVE_PATH))
(POLICY(mfs,DOESNT_PRESERVE_PATH))
(POLICY(newest,DOESNT_PRESERVE_PATH))
(POLICY(rand,DOESNT_PRESERVE_PATH));
@@ -45,11 +50,16 @@ namespace mergerfs
CONST_POLICY(invalid);
CONST_POLICY(all);
CONST_POLICY(epall);
CONST_POLICY(epff);
CONST_POLICY(eplfs);
CONST_POLICY(eplus);
CONST_POLICY(epmfs);
CONST_POLICY(eprand);
CONST_POLICY(erofs);
CONST_POLICY(ff);
CONST_POLICY(lfs);
CONST_POLICY(lus);
CONST_POLICY(mfs);
CONST_POLICY(newest);
CONST_POLICY(rand);
+30 -16
View File
@@ -43,11 +43,16 @@ namespace mergerfs
invalid = -1,
BEGIN = 0,
all = BEGIN,
epall,
epff,
eplfs,
eplus,
epmfs,
eprand,
erofs,
ff,
lfs,
lus,
mfs,
newest,
rand,
@@ -61,15 +66,14 @@ namespace mergerfs
struct Func
{
typedef std::string string;
typedef std::size_t size_t;
typedef std::vector<string> strvec;
typedef std::vector<const string*> cstrptrvec;
typedef const string cstring;
typedef const size_t csize_t;
typedef const uint64_t cuint64_t;
typedef const strvec cstrvec;
typedef const Category::Enum::Type CType;
typedef int (*Ptr)(CType,cstrvec &,const char *,csize_t,cstrptrvec &);
typedef int (*Ptr)(CType,cstrvec &,const char *,cuint64_t,cstrptrvec &);
template <CType T>
class Base
@@ -80,7 +84,7 @@ namespace mergerfs
{}
int
operator()(cstrvec &b,const char *c,csize_t d,cstrptrvec &e)
operator()(cstrvec &b,const char *c,cuint64_t d,cstrptrvec &e)
{
return func(T,b,c,d,e);
}
@@ -93,16 +97,21 @@ namespace mergerfs
typedef Base<Category::Enum::create> Create;
typedef Base<Category::Enum::search> Search;
static int invalid(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int all(CType,cstrvec&,const char*,csize_t,cstrptrvec&);
static int eplfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int epmfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int erofs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int ff(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int lfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int mfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int newest(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int rand(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int invalid(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int all(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
static int epall(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
static int epff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int eplfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int eplus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int epmfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int eprand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int erofs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int ff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int lfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int lus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int mfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int newest(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int rand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
};
private:
@@ -161,16 +170,21 @@ namespace mergerfs
static const Policy &find(const Enum::Type);
public:
static const std::vector<Policy> _policies_;
static const Policy * const policies;
static const std::vector<Policy> _policies_;
static const Policy * const policies;
static const Policy &invalid;
static const Policy &all;
static const Policy &epall;
static const Policy &epff;
static const Policy &eplfs;
static const Policy &eplus;
static const Policy &epmfs;
static const Policy &eprand;
static const Policy &erofs;
static const Policy &ff;
static const Policy &lfs;
static const Policy &lus;
static const Policy &mfs;
static const Policy &newest;
static const Policy &rand;
+5 -5
View File
@@ -25,21 +25,21 @@
using std::string;
using std::vector;
using std::size_t;
static
int
_all_create(const vector<string> &basepaths,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
@@ -87,7 +87,7 @@ namespace mergerfs
Policy::Func::all(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
+105
View File
@@ -0,0 +1,105 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
using std::vector;
static
int
_epall_create(const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
}
if(paths.empty())
return POLICY_FAIL_ENOENT;
return POLICY_SUCCESS;
}
static
int
_epall_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
paths.push_back(basepath);
}
if(paths.empty())
return POLICY_FAIL_ENOENT;
return POLICY_SUCCESS;
}
namespace mergerfs
{
int
Policy::Func::epall(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _epall_create(basepaths,fusepath,minfreespace,paths);
return _epall_other(basepaths,fusepath,paths);
}
}
+131
View File
@@ -0,0 +1,131 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
using std::vector;
using mergerfs::Category;
static
int
_epff_create(const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
const string *fallback;
fallback = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
if(fallback == NULL)
fallback = basepath;
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
return POLICY_SUCCESS;
}
if(fallback == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(fallback);
return POLICY_SUCCESS;
}
static
int
_epff_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
paths.push_back(basepath);
return POLICY_SUCCESS;
}
return POLICY_FAIL_ENOENT;
}
static
int
_epff(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _epff_create(basepaths,fusepath,minfreespace,paths);
return _epff_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
Policy::Func::epff(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
rv = _epff(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
return rv;
}
}
+11 -11
View File
@@ -26,33 +26,33 @@
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Category;
static
int
_eplfs_create(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
size_t eplfs;
uint64_t eplfs;
const string *eplfsbasepath;
eplfs = std::numeric_limits<size_t>::max();
eplfs = std::numeric_limits<uint64_t>::max();
eplfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
@@ -80,14 +80,14 @@ _eplfs_other(const vector<string> &basepaths,
vector<const string*> &paths)
{
string fullpath;
size_t eplfs;
uint64_t eplfs;
const string *eplfsbasepath;
eplfs = std::numeric_limits<size_t>::max();
eplfs = std::numeric_limits<uint64_t>::max();
eplfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
@@ -116,7 +116,7 @@ int
_eplfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
@@ -131,7 +131,7 @@ namespace mergerfs
Policy::Func::eplfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
+145
View File
@@ -0,0 +1,145 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <limits>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
using std::vector;
using mergerfs::Category;
static
int
_eplus_create(const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
uint64_t eplus;
const string *eplusbasepath;
eplus = std::numeric_limits<uint64_t>::max();
eplusbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
uint64_t spaceavail;
uint64_t spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail,spaceused))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceused >= eplus)
continue;
eplus = spaceused;
eplusbasepath = basepath;
}
if(eplusbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(eplusbasepath);
return POLICY_SUCCESS;
}
static
int
_eplus_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
uint64_t eplus;
const string *eplusbasepath;
eplus = 0;
eplusbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
uint64_t spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceused(*basepath,spaceused))
continue;
if(spaceused >= eplus)
continue;
eplus = spaceused;
eplusbasepath = basepath;
}
if(eplusbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(eplusbasepath);
return POLICY_SUCCESS;
}
static
int
_eplus(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _eplus_create(basepaths,fusepath,minfreespace,paths);
return _eplus_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
Policy::Func::eplus(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
rv = _eplus(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::lus(type,basepaths,fusepath,minfreespace,paths);
return rv;
}
}
+17 -12
View File
@@ -16,6 +16,7 @@
#include <errno.h>
#include <limits>
#include <string>
#include <vector>
@@ -25,35 +26,38 @@
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Category;
static
int
_epmfs_create(const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
size_t epmfs;
uint64_t epmfs;
const string *epmfsbasepath;
epmfs = 0;
epmfs = std::numeric_limits<uint64_t>::min();
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceavail < epmfs)
continue;
@@ -76,14 +80,14 @@ _epmfs_other(const vector<string> &basepaths,
vector<const string*> &paths)
{
string fullpath;
size_t epmfs;
uint64_t epmfs;
const string *epmfsbasepath;
epmfs = 0;
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
@@ -112,10 +116,11 @@ int
_epmfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _epmfs_create(basepaths,fusepath,paths);
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
return _epmfs_other(basepaths,fusepath,paths);
}
@@ -126,12 +131,12 @@ namespace mergerfs
Policy::Func::epmfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
rv = _epmfs(type,basepaths,fusepath,paths);
rv = _epmfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
+46
View File
@@ -0,0 +1,46 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <string>
#include <vector>
#include <algorithm>
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
namespace mergerfs
{
int
Policy::Func::eprand(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
rv = Policy::Func::epall(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_SUCCEEDED(rv))
std::random_shuffle(paths.begin(),paths.end());
return rv;
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ namespace mergerfs
Policy::Func::erofs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
return POLICY_FAIL_ERRNO(EROFS);
+5 -5
View File
@@ -25,12 +25,11 @@
using std::string;
using std::vector;
using std::size_t;
static
int
_ff_create(const vector<string> &basepaths,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
const string *fallback;
@@ -39,10 +38,11 @@ _ff_create(const vector<string> &basepaths,
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
@@ -95,7 +95,7 @@ namespace mergerfs
Policy::Func::ff(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
+1 -2
View File
@@ -23,7 +23,6 @@
using std::string;
using std::vector;
using std::size_t;
namespace mergerfs
{
@@ -31,7 +30,7 @@ namespace mergerfs
Policy::Func::invalid(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
return POLICY_FAIL_ERRNO(EINVAL);
+11 -11
View File
@@ -26,28 +26,28 @@
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Category;
static
int
_lfs_create(const vector<string> &basepaths,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
size_t lfs;
uint64_t lfs;
const string *lfsbasepath;
lfs = std::numeric_limits<size_t>::max();
lfs = std::numeric_limits<uint64_t>::max();
lfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
@@ -75,14 +75,14 @@ _lfs_other(const vector<string> &basepaths,
vector<const string*> &paths)
{
string fullpath;
size_t lfs;
uint64_t lfs;
const string *lfsbasepath;
lfs = std::numeric_limits<size_t>::max();
lfs = std::numeric_limits<uint64_t>::max();
lfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
@@ -111,7 +111,7 @@ int
_lfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
@@ -127,7 +127,7 @@ namespace mergerfs
Policy::Func::lfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
+140
View File
@@ -0,0 +1,140 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <limits>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
using std::string;
using std::vector;
using mergerfs::Category;
static
int
_lus_create(const vector<string> &basepaths,
const uint64_t minfreespace,
vector<const string*> &paths)
{
string fullpath;
uint64_t lus;
const string *lusbasepath;
lus = std::numeric_limits<uint64_t>::max();
lusbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
uint64_t spaceused;
uint64_t spaceavail;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail,spaceused))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceused >= lus)
continue;
lus = spaceused;
lusbasepath = basepath;
}
if(lusbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(lusbasepath);
return POLICY_SUCCESS;
}
static
int
_lus_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
uint64_t lus;
const string *lusbasepath;
lus = 0;
lusbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
uint64_t spaceused;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceused(*basepath,spaceused))
continue;
if(spaceused >= lus)
continue;
lus = spaceused;
lusbasepath = basepath;
}
if(lusbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(lusbasepath);
return POLICY_SUCCESS;
}
static
int
_lus(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _lus_create(basepaths,minfreespace,paths);
return _lus_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
Policy::Func::lus(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
rv = _lus(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
return rv;
}
}
+7 -7
View File
@@ -25,7 +25,6 @@
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Category;
static
@@ -34,7 +33,7 @@ _mfs_create(const vector<string> &basepaths,
vector<const string*> &paths)
{
string fullpath;
size_t mfs;
uint64_t mfs;
const string *mfsbasepath;
mfs = 0;
@@ -42,10 +41,11 @@ _mfs_create(const vector<string> &basepaths,
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
uint64_t spaceavail;
uint64_t _spaceused;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail))
if(!fs::info(*basepath,readonly,spaceavail,_spaceused))
continue;
if(readonly)
continue;
@@ -71,14 +71,14 @@ _mfs_other(const vector<string> &basepaths,
vector<const string*> &paths)
{
string fullpath;
size_t mfs;
uint64_t mfs;
const string *mfsbasepath;
mfs = 0;
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
@@ -121,7 +121,7 @@ namespace mergerfs
Policy::Func::mfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
+1 -2
View File
@@ -28,7 +28,6 @@
using std::string;
using std::vector;
using std::size_t;
static
int
@@ -111,7 +110,7 @@ namespace mergerfs
Policy::Func::newest(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
+1 -2
View File
@@ -25,7 +25,6 @@
using std::string;
using std::vector;
using std::size_t;
namespace mergerfs
{
@@ -33,7 +32,7 @@ namespace mergerfs
Policy::Func::rand(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
const uint64_t minfreespace,
vector<const string*> &paths)
{
int rv;
+1 -1
View File
@@ -56,7 +56,7 @@ static
int
_readlink(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
char *buf,
const size_t size)
+1 -1
View File
@@ -73,7 +73,7 @@ static
int
_removexattr(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const char *attrname)
{
+7 -7
View File
@@ -104,7 +104,7 @@ int
_rename_create_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
@@ -146,7 +146,7 @@ static
int
_clonepath(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &dstbasepath,
const string &fusedirpath)
{
@@ -170,7 +170,7 @@ int
_clonepath_if_would_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath)
@@ -196,7 +196,7 @@ void
_rename_preserve_path_core(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const vector<const string*> &oldbasepaths,
const string &oldbasepath,
const char *oldfusepath,
@@ -243,7 +243,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
@@ -296,8 +296,8 @@ namespace mergerfs
oldpath,
newpath);
return _rename_create_path(config.rename,
config.create,
return _rename_create_path(config.getattr,
config.rename,
config.srcmounts,
config.minfreespace,
oldpath,
+1 -1
View File
@@ -68,7 +68,7 @@ static
int
_rmdir(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath)
{
int rv;
+2 -2
View File
@@ -172,7 +172,7 @@ _setxattr_minfreespace(Config &config,
if((flags & XATTR_CREATE) == XATTR_CREATE)
return -EEXIST;
rv = num::to_size_t(attrval,config.minfreespace);
rv = num::to_uint64_t(attrval,config.minfreespace);
if(rv == -1)
return -EINVAL;
@@ -335,7 +335,7 @@ static
int
_setxattr(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const char *attrname,
const char *attrval,
+9 -1
View File
@@ -47,9 +47,17 @@ namespace StatVFS
static
inline
fsblkcnt_t
uint64_t
spaceavail(const struct statvfs &st)
{
return (st.f_frsize * st.f_bavail);
}
static
inline
uint64_t
spaceused(const struct statvfs &st)
{
return (st.f_frsize * (st.f_blocks - st.f_bavail));
}
}
+1 -1
View File
@@ -84,7 +84,7 @@ int
_symlink(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldpath,
const char *newpath)
{
+1 -1
View File
@@ -71,7 +71,7 @@ static
int
_truncate(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const off_t size)
{
+1 -1
View File
@@ -68,7 +68,7 @@ static
int
_unlink(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath)
{
int rv;
+1 -1
View File
@@ -71,7 +71,7 @@ static
int
_utimens(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const timespec ts[2])
{
+1 -1
View File
@@ -42,7 +42,7 @@ _write_buf(const int fd,
fuse_bufvec &src,
const off_t offset)
{
size_t size = fuse_buf_size(&src);
size_t size = fuse_buf_size(&src);
fuse_bufvec dst = FUSE_BUFVEC_INIT(size);
const fuse_buf_copy_flags cpflags =
(fuse_buf_copy_flags)(FUSE_BUF_SPLICE_MOVE|FUSE_BUF_SPLICE_NONBLOCK);