Compare commits

...
48 Commits
Author SHA1 Message Date
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
Antonio SJ Musumeci 8ac3518725 Merge pull request #244 from trapexit/gitdebcl
fix building of platform specific deb packages
2016-03-01 00:19:59 -05:00
Antonio SJ Musumeci f4a4cc5812 fix building of platform specific deb packages 2016-03-01 00:19:05 -05:00
Antonio SJ Musumeci b93783ede0 Merge pull request #243 from trapexit/git2dbcl
fix printing of versions with no changes
2016-02-29 23:56:29 -05:00
Antonio SJ Musumeci ef4c583b3f fix printing of versions with no changes 2016-02-29 23:55:36 -05:00
Antonio SJ Musumeci 6d049c16d1 Merge pull request #242 from trapexit/statvfs
clearly separate usage of statvfs from stat for file existance
2016-02-29 23:11:00 -05:00
Antonio SJ Musumeci 4ecf3c5797 clearly separate usage of statvfs from stat for file existance
Used statvfs to also check for existance vs lstat. On dead symlinks
this resulted in ENOENT making certain functions fail.

closes #239
2016-02-29 23:04:59 -05:00
Antonio SJ Musumeci 4a63c000ca Merge pull request #241 from trapexit/policy-ff
add minfreespace checks to policy ff's create and remove fwfs
2016-02-29 18:15:12 -05:00
Antonio SJ Musumeci 779143f4b6 add minfreespace checks to policy ff's create and remove fwfs
fwfs is now covered by ff with the minfreespace and readonly checks
2016-02-29 18:06:59 -05:00
Antonio SJ Musumeci ccd3b5d2d0 Merge pull request #240 from trapexit/readme
update readme with minfreespace and readonly details
2016-02-29 15:15:10 -05:00
Antonio SJ Musumeci 4d7148cdd1 update readme with minfreespace and readonly details 2016-02-29 15:14:31 -05:00
Antonio SJ Musumeci 98a051b161 Merge pull request #238 from trapexit/policy-all
add readonly and minfreespace filters to all policy for creates. clos…
2016-02-29 10:55:55 -05:00
Antonio SJ Musumeci 14886a27f4 add readonly and minfreespace filters to all policy for creates. closes #236 2016-02-29 10:15:53 -05:00
Antonio SJ Musumeci 81b9918f6b Merge pull request #237 from trapexit/renamefix 2016-02-26 17:18:39 -05:00
Antonio SJ Musumeci 9819cf6133 fix clonepath being called on wrong source 2016-02-26 17:16:09 -05:00
Antonio SJ Musumeci c5e584fa5a Merge pull request #235 from trapexit/changeloger
fix creation of changelog
2016-02-25 17:53:24 -05:00
Antonio SJ Musumeci c56b488c8d fix creation of changelog 2016-02-25 17:52:47 -05:00
Antonio SJ Musumeci cd50a0b0c8 Merge pull request #234 from trapexit/renametweaks
normalize error handling in rename policy
2016-02-24 17:11:58 -05:00
Antonio SJ Musumeci e593927095 normalize error handling in rename policy 2016-02-24 17:10:56 -05:00
Antonio SJ Musumeci 12251cf7c2 Merge pull request #233 from trapexit/ffopt
ff policy tweaks
2016-02-24 13:02:24 -05:00
Antonio SJ Musumeci 7c85cd906a ff policy tweaks 2016-02-24 12:40:02 -05:00
Antonio SJ Musumeci 32c4b1ad1c Merge pull request #232 from trapexit/version
override standard libfuse version flag
2016-02-24 08:39:56 -05:00
Antonio SJ Musumeci 5cf3bb7c98 override standard libfuse version flag 2016-02-24 06:36:33 -05:00
Antonio SJ Musumeci 3f8a6525b3 Merge pull request #231 from trapexit/fstweaks
minor tweaks to filesystem utility functions
2016-02-23 12:35:42 -05:00
Antonio SJ Musumeci 25a039942c minor tweaks to filesystem utility functions 2016-02-23 12:28:20 -05:00
Antonio SJ Musumeci 400537d711 Merge pull request #230 from trapexit/findonfs
use stat/2 rather than statvfs/2 to find file drive
2016-02-23 12:07:31 -05:00
Antonio SJ Musumeci 792c9b9808 use stat/2 rather than statvfs/2 to find file drive 2016-02-23 12:06:16 -05:00
Antonio SJ Musumeci 476a8a50ea Merge pull request #228 from trapexit/readme
update / tweak readme
2016-02-21 18:31:02 -05:00
Antonio SJ Musumeci a698a8a545 update / tweak readme 2016-02-21 18:30:25 -05:00
Antonio SJ Musumeci 5b06bb24fb Merge pull request #227 from trapexit/policy-cleanup
remove unnecessary policies
2016-02-21 18:25:11 -05:00
Antonio SJ Musumeci d4ec341c4f remove unnecessary policies 2016-02-21 18:24:15 -05:00
Antonio SJ Musumeci 1bbe3a8879 Merge pull request #226 from trapexit/readonly
ignore drives mounted as readonly from create policies. closes #224
2016-02-21 14:35:53 -05:00
Antonio SJ Musumeci 5813d1e477 ignore drives mounted as readonly from create policies. closes #224 2016-02-21 14:34:40 -05:00
Antonio SJ Musumeci 81e77216fc Merge pull request #225 from trapexit/eplfs-readme
add eplfs info to readme
2016-02-18 13:32:44 -05:00
Antonio SJ Musumeci a4e60d7471 add eplfs info to readme 2016-02-18 13:32:30 -05:00
27 changed files with 986 additions and 898 deletions
+3 -5
View File
@@ -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)
+83 -101
View File
@@ -1,6 +1,6 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2016-01-21
% 2016-02-21
# NAME
@@ -25,6 +25,7 @@ mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
* Opportunistic credential caching
* Works with heterogeneous filesystem types
* Handling of writes to full drives
* Handles pool of readonly and read/write drives
# OPTIONS
@@ -32,7 +33,7 @@ mergerfs -o&lt;options&gt; &lt;srcmounts&gt; &lt;mountpoint&gt;
* **defaults**: a shortcut for FUSE's **atomic_o_trunc**, **auto_cache**, **big_writes**, **default_permissions**, **splice_move**, **splice_read**, and **splice_write**. These options seem to provide the best performance.
* **direct_io**: causes FUSE to bypass an addition caching step which can increase write speeds at the detriment of read speed.
* **minfreespace**: the minimum space value used for the **lfs**, **fwfs**, and **epmfs** policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively. (default: 4G)
* **minfreespace**: the minimum space value used for creation policies. Understands 'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte respectively. (default: 4G)
* **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**
@@ -58,11 +59,13 @@ In /etc/fstab it'd look like the following:
**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.
# POLICIES
# FUNCTIONS / POLICIES / CATEGORIES
Filesystem calls are broken up into 3 categories: **action**, **create**, **search**. There are also some calls which have no policy attached due to state being kept between calls. These categories can be assigned a policy which dictates how **mergerfs** behaves. Any policy can be assigned to a category though some aren't terribly practical. For instance: **rand** (Random) may be useful for **create** but could lead to very odd behavior if used for **search**.
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`.
#### Functional classifications ####
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.
#### Function / Category classifications ####
| Category | FUSE Functions |
|----------|----------------|
@@ -71,22 +74,23 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear
| search | access, getattr, getxattr, ioctl, listxattr, open, readlink |
| N/A | fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release, statfs, write |
**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) then **getattr** will be used.
#### Policy descriptions ####
Most policies when called to create will filter out drives which are readonly or have less than **minfreespace**.
| Policy | Description |
|--------------|-------------|
| ff (first found) | Given the order of the drives act on the first one found (regardless if stat would return EACCES). |
| ffwp (first found w/ permissions) | Given the order of the drives act on the first one found which you have access (stat does not error with EACCES). |
| newest (newest file) | If multiple files exist return the one with the most recent mtime. |
| mfs (most free space) | Use the drive with the most free space available. |
| epmfs (existing path, most free space) | If the path exists on multiple drives use the one with the most free space and is greater than **minfreespace**. If no drive has at least **minfreespace** then fallback to **mfs**. |
| fwfs (first with free space) | Pick the first drive which has at least **minfreespace**. |
| lfs (least free space) | Pick the drive with least available space but more than **minfreespace**. |
| rand (random) | Pick an existing drive at random. |
| all | Applies action to all found. For searches it will behave like first found **ff**. |
| enosys, einval, enotsup, exdev, erofs | Exclusively return `-1` with `errno` set to the respective value. Useful for debugging other applications' behavior to errors. |
| 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**. |
| 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. |
| rand (random) | Calls **all** and then randomizes. |
#### Defaults ####
@@ -102,7 +106,7 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear
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)
* If using a `create` policy which tries to preserve directory paths (epmfs,eplfs)
* Using the `rename` policy get the list of files to rename
* For each file attempt rename:
* If failure with ENOENT run `create` policy
@@ -113,7 +117,7 @@ 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
* 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:
@@ -140,7 +144,7 @@ It could be extended to offer the ability to see all files found. Perhaps concat
#### statvfs ####
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple mount points on the same drive will not result in double counting it's space. It is possible due to a race condition that the same drive could be double counted but it's rather unlikely.
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple sources on the same drive will not result in double counting it's space.
# BUILDING
@@ -197,59 +201,6 @@ Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/
Use `xattr -l /mount/point/.mergerfs` to see all supported keys.
##### Example #####
```
[trapexit:/tmp/mount] $ xattr -l .mergerfs
user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.moveonenospc: false
user.mergerfs.policies: all,einval,enosys,enotsup,epmfs,erofs,exdev,ff,ffwp,fwfs,lfs,mfs,newest,rand
user.mergerfs.version: x.y.z
user.mergerfs.category.action: all
user.mergerfs.category.create: epmfs
user.mergerfs.category.search: ff
user.mergerfs.func.access: ff
user.mergerfs.func.chmod: all
user.mergerfs.func.chown: all
user.mergerfs.func.create: epmfs
user.mergerfs.func.getattr: ff
user.mergerfs.func.getxattr: ff
user.mergerfs.func.link: all
user.mergerfs.func.listxattr: ff
user.mergerfs.func.mkdir: epmfs
user.mergerfs.func.mknod: epmfs
user.mergerfs.func.open: ff
user.mergerfs.func.readlink: ff
user.mergerfs.func.removexattr: all
user.mergerfs.func.rename: all
user.mergerfs.func.rmdir: all
user.mergerfs.func.setxattr: all
user.mergerfs.func.symlink: epmfs
user.mergerfs.func.truncate: all
user.mergerfs.func.unlink: all
user.mergerfs.func.utimens: all
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
ff
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search ffwp .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
ffwp
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/a:/tmp/b:/tmp/c
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/c
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/a:/tmp/b:/tmp/c
```
##### 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.
@@ -279,7 +230,36 @@ Ouput: **true** or **false**
Input: short policy string as described elsewhere in this document
Output: the policy string except for categories where its funcs have multiple types. In that case it will be a comma separated list.
Output: the policy string except for categories where its funcs have multiple types. In that case it will be a comma separated list
##### Example #####
```
[trapexit:/tmp/mount] $ xattr -l .mergerfs
user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.moveonenospc: false
...
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
ff
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search newest .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
newest
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/a:/tmp/b:/tmp/c
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/c
[trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
[trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
/tmp/a:/tmp/b:/tmp/c
```
#### mergerfs file xattrs ####
@@ -306,13 +286,15 @@ A B C
# TOOLING
Find extra 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.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.
* Detailed guides to setting up a backup solution using mergerfs and other technologies: https://github.com/trapexit/backup-and-recovery-howtos
* 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.
* 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.
@@ -320,7 +302,7 @@ Find extra tooling to help with managing `mergerfs` at: https://github.com/trape
* An example: [Kodi](http://kodi.tv) and [Plex](http://plex.tv) can use directory [mtime](http://linux.die.net/man/2/stat) to more efficiently determine whether to scan for new content rather than simply performing a full scan. If using the current default **getattr** policy of **ff** its possible **Kodi** will miss an update on account of it returning the first directory found's **stat** info and its a later directory on another mount which had the **mtime** recently updated. To fix this you will want to set **func.getattr=newest**. Remember though that this is just **stat**. If the file is later **open**'ed or **unlink**'ed and the policy is different for those then a completely different file or directory could be acted on.
* Due to previously mentioned issues its generally best to set **category** wide policies rather than individual **func**'s. This will help limit the confusion of tools such as [rsync](http://linux.die.net/man/1/rsync).
# Known Issues / Bugs
# KNOWN ISSUES / BUGS
#### Trashing files occasionally fails
@@ -328,23 +310,23 @@ This is the same issue as with Samba. `rename` returns `EXDEV` (in our case that
To create a `$topdir/.Trash` directory as defined in the standard use the [mergerfs-tools](https://github.com/trapexit/mergerfs-tools) tool `mergerfs.mktrash`.
#### Samba
* Moving files or directories between some directories on a SMB share fail with IO errors.
Workaround: Copy the file/directory and then remove the original rather than move.
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed to handle certain error codes correctly. Particularly **STATUS_NOT_SAME_DEVICE** which comes from the **EXDEV** which is returned by **rename** when the call is crossing mount points. When a program gets an **EXDEV** it needs to explicitly take an alternate action to accomplish it's goal. In the case of **mv** or similar it tries **rename** and on **EXDEV** falls back to a manual copying of data between the two locations and unlinking the source. In these older versions of GVFS-fuse if it received **EXDEV** it would translate that into **EIO**. This would cause **mv** or most any application attempting to move files around on that SMB share to fail with a IO error.
[GVFS-fuse v1.22.0](https://bugzilla.gnome.org/show_bug.cgi?id=734568) and above fixed this issue but a large number of systems use the older release. On Ubuntu the version can be checked by issuing `apt-cache showpkg gvfs-fuse`. Most distros released in 2015 seem to have the updated release and will work fine but older systems may not. Upgrading gvfs-fuse or the distro in general will address the problem.
In Apple's MacOSX 10.9 they replaced Samba (client and server) with their own product. It appears their new client does not handle **EXDEV** either and responds similar to older release of gvfs on Linux.
#### Samba: Moving files / directories fails
#### Supplemental groups
* Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. Each thread will query the supplemental groups for a user when that particular thread needs to change credentials and will keep that data for the lifetime of the mount or thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
The gid cache uses fixed storage to simplify the design and be compatible with older systems which may not have C++11 compilers (as the original design required). There is enough storage for 256 users' supplemental groups. Each user is allowed upto 32 supplemental groups. Linux >= 2.6.3 allows upto 65535 groups per user but most other *nixs allow far less. NFS allowing only 16. The system does handle overflow gracefully. If the user has more than 32 supplemental groups only the first 32 will be used. If more than 256 users are using the system when an uncached user is found it will evict an existing user's cache at random. So long as there aren't more than 256 active users this should be fine. If either value is too low for your needs you will have to modify `gidcache.hpp` to increase the values. Note that doing so will increase the memory needed by each thread.
Workaround: Copy the file/directory and then remove the original rather than move.
#### mergerfs / libfuse crashes
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed to handle certain error codes correctly. Particularly **STATUS_NOT_SAME_DEVICE** which comes from the **EXDEV** which is returned by **rename** when the call is crossing mount points. When a program gets an **EXDEV** it needs to explicitly take an alternate action to accomplish it's goal. In the case of **mv** or similar it tries **rename** and on **EXDEV** falls back to a manual copying of data between the two locations and unlinking the source. In these older versions of GVFS-fuse if it received **EXDEV** it would translate that into **EIO**. This would cause **mv** or most any application attempting to move files around on that SMB share to fail with a IO error.
[GVFS-fuse v1.22.0](https://bugzilla.gnome.org/show_bug.cgi?id=734568) and above fixed this issue but a large number of systems use the older release. On Ubuntu the version can be checked by issuing `apt-cache showpkg gvfs-fuse`. Most distros released in 2015 seem to have the updated release and will work fine but older systems may not. Upgrading gvfs-fuse or the distro in general will address the problem.
In Apple's MacOSX 10.9 they replaced Samba (client and server) with their own product. It appears their new client does not handle **EXDEV** either and responds similar to older release of gvfs on Linux.
#### Supplemental user groups
Due to the overhead of [getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs utilizes a cache. This cache is opportunistic and per thread. Each thread will query the supplemental groups for a user when that particular thread needs to change credentials and will keep that data for the lifetime of the thread. This means that if a user is added to a group it may not be picked up without the restart of mergerfs. However, since the high level FUSE API's (at least the standard version) thread pool dynamically grows and shrinks it's possible that over time a thread will be killed and later a new thread with no cache will start and query the new data.
The gid cache uses fixed storage to simplify the design and be compatible with older systems which may not have C++11 compilers. There is enough storage for 256 users' supplemental groups. Each user is allowed upto 32 supplemental groups. Linux >= 2.6.3 allows upto 65535 groups per user but most other *nixs allow far less. NFS allowing only 16. The system does handle overflow gracefully. If the user has more than 32 supplemental groups only the first 32 will be used. If more than 256 users are using the system when an uncached user is found it will evict an existing user's cache at random. So long as there aren't more than 256 active users this should be fine. If either value is too low for your needs you will have to modify `gidcache.hpp` to increase the values. Note that doing so will increase the memory needed by each thread.
#### mergerfs or libfuse crashing
If suddenly the mergerfs mount point disappears and `Transport endpoint is not connected` is returned when attempting to perform actions within the mount directory **and** the version of libfuse (use `mergerfs -v` to find the version) is older than `2.9.4` its likely due to a bug in libfuse. Affected versions of libfuse can be found in Debian Wheezy, Ubuntu Precise and others.
@@ -358,27 +340,27 @@ mhddfs is no longer maintained and has some known stability and security issues
#### Why use mergerfs over aufs?
While aufs can offer better peak performance mergerfs offers more configurability and is generally easier to use. mergerfs also doesn't offer the overlay features which tends to result in whiteout files being left around the underlying filesystems.
While aufs can offer better peak performance mergerfs offers more configurability and is generally easier to use. mergerfs however doesn't offer the overlay features which tends to result in whiteout files being left around the underlying filesystems.
#### Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
A single drive failure will lead to full pool failure without additional redundency. mergerfs performance a similar behavior without the catastrophic failure and lack of recovery. Drives can fail and all other data will continue to be accessable.
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.
#### 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.
[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.
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.
Linux does not support [pthread_setugid_np](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) but user and group IDs are a per-thread attribute though documentation on that fact or how to manipulate them is not well distributed. From the **4.00** release of the Linux man-pages project for [setuid](http://man7.org/linux/man-pages/man2/setuid.2.html)
Linux does not support [pthread_setugid_np](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html) but user and group IDs are a per-thread attribute though documentation on that fact or how to manipulate them is not well distributed. From the **4.00** release of the Linux man-pages project for [setuid](http://man7.org/linux/man-pages/man2/setuid.2.html).
> At the kernel level, user IDs and group IDs are a per-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for setuid()) employ a signal-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see nptl(7).
> At the kernel level, user IDs and group IDs are a per-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for setuid()) employ a signal-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see nptl(7).
Turns out the setreuid syscalls apply only to the thread. GLIBC hides this away using RT signals to inform all threads to change credentials. Taking after **Samba** mergerfs uses **syscall(SYS_setreuid,...)** to set the callers credentials for that thread only. Jumping back to **root** as necessary should escalated privileges be needed (for instance: to clone paths).
Turns out the setreuid syscalls apply only to the thread. GLIBC hides this away using RT signals to inform all threads to change credentials. Taking after **Samba** mergerfs uses **syscall(SYS_setreuid,...)** to set the callers credentials for that thread only. Jumping back to **root** as necessary should escalated privileges be needed (for instance: to clone paths).
For non-Linux systems mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allow multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well. As new platforms are supported if they offer per thread credentials those APIs will be adopted.
For non-Linux systems mergerfs uses a read-write lock and changes credentials only when necessary. If multiple threads are to be user X then only the first one will need to change the processes credentials. So long as the other threads need to be user X they will take a readlock allow multiple threads to share the credentials. Once a request comes in to run as user Y that thread will attempt a write lock and change to Y's credentials when it can. If the ability to give writers priority is supported then that flag will be used so threads trying to change credentials don't starve. This isn't the best solution but should work reasonably well. As new platforms are supported if they offer per thread credentials those APIs will be adopted.
# SUPPORT
+169 -135
View File
@@ -1,5 +1,5 @@
.\"t
.TH "mergerfs" "1" "2016\-01\-21" "mergerfs user manual" ""
.TH "mergerfs" "1" "2016\-02\-21" "mergerfs user manual" ""
.SH NAME
.PP
mergerfs \- another (FUSE based) union filesystem
@@ -31,6 +31,8 @@ Opportunistic credential caching
Works with heterogeneous filesystem types
.IP \[bu] 2
Handling of writes to full drives
.IP \[bu] 2
Handles pool of readonly and read/write drives
.SH OPTIONS
.SS options
.IP \[bu] 2
@@ -42,8 +44,8 @@ These options seem to provide the best performance.
\f[B]direct_io\f[]: causes FUSE to bypass an addition caching step which
can increase write speeds at the detriment of read speed.
.IP \[bu] 2
\f[B]minfreespace\f[]: the minimum space value used for the
\f[B]lfs\f[], \f[B]fwfs\f[], and \f[B]epmfs\f[] policies.
\f[B]minfreespace\f[]: the minimum space value used for creation
policies.
Understands \[aq]K\[aq], \[aq]M\[aq], and \[aq]G\[aq] to represent
kilobyte, megabyte, and gigabyte respectively.
(default: 4G)
@@ -101,19 +103,22 @@ In /etc/fstab it\[aq]d look like the following:
\f[B]NOTE:\f[] 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.
.SH POLICIES
.SH FUNCTIONS / POLICIES / CATEGORIES
.PP
Filesystem calls are broken up into 3 categories: \f[B]action\f[],
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[].
There are also some calls which have no policy attached due to state
being kept between calls.
These categories can be assigned a policy which dictates how
\f[B]mergerfs\f[] behaves.
Any policy can be assigned to a category though some aren\[aq]t terribly
practical.
For instance: \f[B]rand\f[] (Random) may be useful for \f[B]create\f[]
but could lead to very odd behavior if used for \f[B]search\f[].
.SS Functional classifications
These 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[].
.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.
.SS Function / Category classifications
.PP
.TS
tab(@);
@@ -148,13 +153,17 @@ statfs, write
T}
.TE
.PP
\f[B]ioctl\f[] behaves differently if its acting on a directory.
Due to FUSE limitations \f[B]ioctl\f[] behaves differently if its acting
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.
.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.
@@ -165,63 +174,65 @@ Description
T}
_
T{
ff (first found)
all
T}@T{
Given the order of the drives act on the first one found (regardless if
stat would return EACCES).
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]minfreespace\f[].
\f[B]create\f[] filters the same way but acts like \f[B]ff\f[].
T}
T{
ffwp (first found w/ permissions)
eplfs (existing path, least free space)
T}@T{
Given the order of the drives act on the first one found which you have
access (stat does not error with EACCES).
T}
T{
newest (newest file)
T}@T{
If multiple files exist return the one with the most recent mtime.
T}
T{
mfs (most free space)
T}@T{
Use the drive with the most free space available.
If the path exists on multiple drives use the one with the least free
space.
Falls back to \f[B]lfs\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 and is greater than \f[B]minfreespace\f[].
If no drive has at least \f[B]minfreespace\f[] then fallback to
\f[B]mfs\f[].
space.
Falls back to \f[B]mfs\f[].
T}
T{
fwfs (first with free space)
erofs
T}@T{
Pick the first drive which has at least \f[B]minfreespace\f[].
Exclusively return \f[B]\-1\f[] with \f[B]errno\f[] set to
\f[B]EROFS\f[].
By setting \f[B]create\f[] functions to this you can in effect turn the
filesystem readonly.
T}
T{
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.
T}
T{
lfs (least free space)
T}@T{
Pick the drive with least available space but more than
Pick the drive with the least available free space but more 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.
Falls back to \f[B]ff\f[].
T}
T{
newest (newest file)
T}@T{
Pick the file / directory with the largest mtime.
T}
T{
rand (random)
T}@T{
Pick an existing drive at random.
T}
T{
all
T}@T{
Applies action to all found.
For searches it will behave like first found \f[B]ff\f[].
T}
T{
enosys, einval, enotsup, exdev, erofs
T}@T{
Exclusively return \f[C]\-1\f[] with \f[C]errno\f[] set to the
respective value.
Useful for debugging other applications\[aq] behavior to errors.
Calls \f[B]all\f[] and then randomizes.
T}
.TE
.SS Defaults
@@ -276,7 +287,8 @@ 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)
If using a \f[C]create\f[] policy which tries to preserve directory
paths (epmfs,eplfs)
.IP \[bu] 2
Using the \f[C]rename\f[] policy get the list of files to rename
.IP \[bu] 2
@@ -305,7 +317,8 @@ 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[C]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
.IP \[bu] 2
@@ -367,11 +380,8 @@ drives based on the fragment size and sums the number of adjusted blocks
and inodes.
This means you will see the combined space of all sources.
Total, used, and free.
The sources however are dedupped based on the drive so multiple mount
points on the same drive will not result in double counting it\[aq]s
space.
It is possible due to a race condition that the same drive could be
double counted but it\[aq]s rather unlikely.
The sources however are dedupped based on the drive so multiple sources
on the same drive will not result in double counting it\[aq]s space.
.SH BUILDING
.PP
\f[B]NOTE:\f[] Prebuilt packages can be found at:
@@ -441,60 +451,6 @@ still work.
.PP
Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
keys.
.SS Example
.IP
.nf
\f[C]
[trapexit:/tmp/mount]\ $\ xattr\ \-l\ .mergerfs
user.mergerfs.srcmounts:\ /tmp/a:/tmp/b
user.mergerfs.minfreespace:\ 4294967295
user.mergerfs.moveonenospc:\ false
user.mergerfs.policies:\ all,einval,enosys,enotsup,epmfs,erofs,exdev,ff,ffwp,fwfs,lfs,mfs,newest,rand
user.mergerfs.version:\ x.y.z
user.mergerfs.category.action:\ all
user.mergerfs.category.create:\ epmfs
user.mergerfs.category.search:\ ff
user.mergerfs.func.access:\ ff
user.mergerfs.func.chmod:\ all
user.mergerfs.func.chown:\ all
user.mergerfs.func.create:\ epmfs
user.mergerfs.func.getattr:\ ff
user.mergerfs.func.getxattr:\ ff
user.mergerfs.func.link:\ all
user.mergerfs.func.listxattr:\ ff
user.mergerfs.func.mkdir:\ epmfs
user.mergerfs.func.mknod:\ epmfs
user.mergerfs.func.open:\ ff
user.mergerfs.func.readlink:\ ff
user.mergerfs.func.removexattr:\ all
user.mergerfs.func.rename:\ all
user.mergerfs.func.rmdir:\ all
user.mergerfs.func.setxattr:\ all
user.mergerfs.func.symlink:\ epmfs
user.mergerfs.func.truncate:\ all
user.mergerfs.func.unlink:\ all
user.mergerfs.func.utimens:\ all
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
ff
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.category.search\ ffwp\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
ffwp
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ +/tmp/c\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/a:/tmp/b:/tmp/c
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ =/tmp/c\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/c
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ \[aq]+</tmp/a:/tmp/b\[aq]\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/a:/tmp/b:/tmp/c
\f[]
.fi
.SS user.mergerfs.srcmounts
.PP
For \f[B]user.mergerfs.srcmounts\f[] there are several instructions
@@ -559,7 +515,37 @@ Input: short policy string as described elsewhere in this document
.PP
Output: the policy string except for categories where its funcs have
multiple types.
In that case it will be a comma separated list.
In that case it will be a comma separated list
.SS Example
.IP
.nf
\f[C]
[trapexit:/tmp/mount]\ $\ xattr\ \-l\ .mergerfs
user.mergerfs.srcmounts:\ /tmp/a:/tmp/b
user.mergerfs.minfreespace:\ 4294967295
user.mergerfs.moveonenospc:\ false
\&...
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
ff
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.category.search\ newest\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
newest
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ +/tmp/c\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/a:/tmp/b:/tmp/c
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ =/tmp/c\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/c
[trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ \[aq]+</tmp/a:/tmp/b\[aq]\ .mergerfs
[trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
/tmp/a:/tmp/b:/tmp/c
\f[]
.fi
.SS mergerfs file xattrs
.PP
While they won\[aq]t show up when using
@@ -598,19 +584,25 @@ A\ B\ C
.fi
.SH TOOLING
.PP
Find extra tooling to help with managing \f[C]mergerfs\f[] at:
Find tooling to help with managing \f[C]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.mktrash: Creates FreeDesktop.org Trash specification compatible
directories on a mergerfs mount
.SH TIPS / NOTES
.IP \[bu] 2
Detailed guides to setting up a backup solution using mergerfs and other
technologies: https://github.com/trapexit/backup\-and\-recovery\-howtos
.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
Since POSIX gives you only error or success on calls its difficult to
@@ -660,12 +652,25 @@ Due to previously mentioned issues its generally best to set
\f[B]func\f[]\[aq]s.
This will help limit the confusion of tools such as
rsync (http://linux.die.net/man/1/rsync).
.SH Known Issues / Bugs
.SS Samba
.IP \[bu] 2
Moving files or directories between some directories on a SMB share fail
with IO errors.
.RS 2
.SH KNOWN ISSUES / BUGS
.SS Trashing files occasionally fails
.PP
This is the same issue as with Samba.
\f[C]rename\f[] returns \f[C]EXDEV\f[] (in our case that will really
only happen with path preserving policies like \f[C]epmfs\f[]) and the
software doesn\[aq]t handle the situtation well.
This is unfortunately a common failure of software which moves files
around.
The standard indicates that an implementation \f[C]MAY\f[] choose to
support non\-user home directory trashing of files (which is a
\f[C]MUST\f[]).
The implementation \f[C]MAY\f[] also support "top directory trashes"
which many probably do.
.PP
To create a \f[C]$topdir/.Trash\f[] directory as defined in the standard
use the mergerfs\-tools (https://github.com/trapexit/mergerfs-tools)
tool \f[C]mergerfs.mktrash\f[].
.SS Samba: Moving files / directories fails
.PP
Workaround: Copy the file/directory and then remove the original rather
than move.
@@ -699,27 +704,24 @@ In Apple\[aq]s MacOSX 10.9 they replaced Samba (client and server) with
their own product.
It appears their new client does not handle \f[B]EXDEV\f[] either and
responds similar to older release of gvfs on Linux.
.RE
.SS Supplemental groups
.IP \[bu] 2
.SS Supplemental user groups
.PP
Due to the overhead of
getgroups/setgroups (http://linux.die.net/man/2/setgroups) mergerfs
utilizes a cache.
This cache is opportunistic and per thread.
Each thread will query the supplemental groups for a user when that
particular thread needs to change credentials and will keep that data
for the lifetime of the mount or thread.
for the lifetime of the thread.
This means that if a user is added to a group it may not be picked up
without the restart of mergerfs.
However, since the high level FUSE API\[aq]s (at least the standard
version) thread pool dynamically grows and shrinks it\[aq]s possible
that over time a thread will be killed and later a new thread with no
cache will start and query the new data.
.RS 2
.PP
The gid cache uses fixed storage to simplify the design and be
compatible with older systems which may not have C++11 compilers (as the
original design required).
compatible with older systems which may not have C++11 compilers.
There is enough storage for 256 users\[aq] supplemental groups.
Each user is allowed upto 32 supplemental groups.
Linux >= 2.6.3 allows upto 65535 groups per user but most other *nixs
@@ -735,11 +737,43 @@ fine.
If either value is too low for your needs you will have to modify
\f[C]gidcache.hpp\f[] to increase the values.
Note that doing so will increase the memory needed by each thread.
.RE
.SH FAQ
.SS mergerfs or libfuse crashing
.PP
\f[I]It\[aq]s mentioned that there are some security issues with mhddfs.
What are they? How does mergerfs address them?\f[]
If suddenly the mergerfs mount point disappears and
\f[C]Transport\ endpoint\ is\ not\ connected\f[] is returned when
attempting to perform actions within the mount directory \f[B]and\f[]
the version of libfuse (use \f[C]mergerfs\ \-v\f[] to find the version)
is older than \f[C]2.9.4\f[] its likely due to a bug in libfuse.
Affected versions of libfuse can be found in Debian Wheezy, Ubuntu
Precise and others.
.PP
In order to fix this please install newer versions of libfuse.
If using a Debian based distro (Debian,Ubuntu,Mint) you can likely just
install newer versions of
libfuse (https://packages.debian.org/unstable/libfuse2) and
fuse (https://packages.debian.org/unstable/fuse) from the repo of a
newer release.
.SH FAQ
.SS Why use mergerfs over mhddfs?
.PP
mhddfs is no longer maintained and has some known stability and security
issues (see below).
.SS Why use mergerfs over aufs?
.PP
While aufs can offer better peak performance mergerfs offers more
configurability and is generally easier to use.
mergerfs however doesn\[aq]t offer the overlay features which tends to
result in whiteout files being left around the underlying filesystems.
.SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation /
striping?
.PP
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.
.SS It\[aq]s mentioned that there are some security issues with mhddfs.
What are they? How does mergerfs address them?
.PP
mhddfs (https://github.com/trapexit/mhddfs) tries to handle being run as
\f[B]root\f[] by calling
@@ -761,7 +795,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.
@@ -775,7 +809,7 @@ pthread_setugid_np (https://developer.apple.com/library/mac/documentation/Darwin
but user and group IDs are a per\-thread attribute though documentation
on that fact or how to manipulate them is not well distributed.
From the \f[B]4.00\f[] release of the Linux man\-pages project for
setuid (http://man7.org/linux/man-pages/man2/setuid.2.html)
setuid (http://man7.org/linux/man-pages/man2/setuid.2.html).
.RS
.PP
At the kernel level, user IDs and group IDs are a per\-thread attribute.
+117 -40
View File
@@ -31,29 +31,103 @@
#include "fs_attr.hpp"
#include "fs_path.hpp"
#include "fs_xattr.hpp"
#include "statvfs_util.hpp"
#include "str.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
namespace fs
{
bool
exists(const string &path,
struct stat &st)
{
int rv;
rv = ::lstat(path.c_str(),&st);
return LSTAT_SUCCEEDED(rv);
}
bool
exists(const string &path)
{
struct stat st;
return exists(path,st);
}
bool
statvfs(const string &path,
struct statvfs &st)
{
int rv;
rv = ::statvfs(path.c_str(),&st);
return STATVFS_SUCCEEDED(rv);
}
bool
info(const string &path,
bool &readonly,
size_t &spaceavail)
{
bool rv;
struct statvfs st;
rv = fs::statvfs(path,st);
if(rv)
{
readonly = StatVFS::readonly(st);
spaceavail = StatVFS::spaceavail(st);
}
return rv;
}
bool
readonly(const string &path)
{
bool rv;
struct statvfs st;
rv = fs::statvfs(path,st);
return (rv && StatVFS::readonly(st));
}
bool
spaceavail(const string &path,
size_t &spaceavail)
{
bool rv;
struct statvfs st;
rv = fs::statvfs(path,st);
if(rv)
spaceavail = StatVFS::spaceavail(st);
return rv;
}
void
findallfiles(const vector<string> &srcmounts,
const char *fusepath,
vector<string> &paths)
{
int rv;
string fullpath;
struct stat st;
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
fs::path::make(&srcmounts[i],fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0)
paths.push_back(fullpath);
if(!fs::exists(fullpath))
continue;
paths.push_back(fullpath);
}
}
@@ -64,28 +138,29 @@ namespace fs
string &basepath)
{
int rv;
dev_t dev;
string fullpath;
unsigned long fsid;
struct statvfs buf;
struct stat st;
rv = ::fstatvfs(fd,&buf);
if(rv == -1)
rv = ::fstat(fd,&st);
if(FSTAT_FAILED(rv))
return -1;
fsid = buf.f_fsid;
dev = st.st_dev;
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
{
fs::path::make(&srcmounts[i],fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&buf);
if(rv == -1)
rv = ::lstat(fullpath.c_str(),&st);
if(FSTAT_FAILED(rv))
continue;
if(buf.f_fsid == fsid)
{
basepath = srcmounts[i];
return 0;
}
if(st.st_dev != dev)
continue;
basepath = srcmounts[i];
return 0;
}
return (errno=ENOENT,-1);
@@ -96,14 +171,19 @@ namespace fs
vector<string> &strs)
{
int flags;
size_t veclen;
glob_t gbuf = {0};
veclen = patterns.size();
if(veclen == 0)
return;
flags = 0;
for(size_t i = 0; i < patterns.size(); i++)
{
glob(patterns[i].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND;
}
glob(patterns[0].c_str(),flags,NULL,&gbuf);
flags = GLOB_APPEND;
for(size_t i = 1; i < veclen; i++)
glob(patterns[i].c_str(),flags,NULL,&gbuf);
for(size_t i = 0; i < gbuf.gl_pathc; ++i)
strs.push_back(gbuf.gl_pathv[i]);
@@ -139,34 +219,31 @@ namespace fs
string &path)
{
fsblkcnt_t mfs;
ssize_t mfsidx;
const string *mfsbasepath;
mfs = 0;
mfsidx = -1;
mfs = 0;
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
int rv;
struct statvfs fsstats;
size_t spaceavail;
const string &basepath = basepaths[i];
rv = ::statvfs(basepath.c_str(),&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
if(!fs::spaceavail(basepath,spaceavail))
continue;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > mfs) && (spaceavail >= minfreespace))
{
mfs = spaceavail;
mfsidx = i;
}
}
if(spaceavail < minfreespace)
continue;
if(spaceavail <= mfs)
continue;
mfs = spaceavail;
mfsbasepath = &basepaths[i];
}
if(mfsidx == -1)
if(mfsbasepath == NULL)
return (errno=ENOENT,-1);
path = basepaths[mfsidx];
path = *mfsbasepath;
return 0;
}
+16
View File
@@ -26,6 +26,22 @@ namespace fs
using std::string;
using std::vector;
bool exists(const string &path,
struct stat &st);
bool exists(const string &path);
bool statvfs(const string &path,
struct statvfs &st);
bool info(const string &path,
bool &readonly,
size_t &spaceavail);
bool readonly(const string &path);
bool spaceavail(const string &path,
size_t &spaceavail);
void findallfiles(const vector<string> &srcmounts,
const char *fusepath,
vector<string> &paths);
+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
@@ -324,6 +324,7 @@ namespace mergerfs
FUSE_OPT_KEY("-h",MERGERFS_OPT_HELP),
FUSE_OPT_KEY("--help",MERGERFS_OPT_HELP),
FUSE_OPT_KEY("-v",MERGERFS_OPT_VERSION),
FUSE_OPT_KEY("-V",MERGERFS_OPT_VERSION),
FUSE_OPT_KEY("--version",MERGERFS_OPT_VERSION),
{NULL,-1U,0}
};
-12
View File
@@ -30,16 +30,10 @@ namespace mergerfs
buildvector<Policy,true>
(POLICY(invalid,DOESNT_PRESERVE_PATH))
(POLICY(all,DOESNT_PRESERVE_PATH))
(POLICY(einval,DOESNT_PRESERVE_PATH))
(POLICY(enosys,DOESNT_PRESERVE_PATH))
(POLICY(enotsup,DOESNT_PRESERVE_PATH))
(POLICY(eplfs,PRESERVES_PATH))
(POLICY(epmfs,PRESERVES_PATH))
(POLICY(erofs,DOESNT_PRESERVE_PATH))
(POLICY(exdev,DOESNT_PRESERVE_PATH))
(POLICY(ff,DOESNT_PRESERVE_PATH))
(POLICY(ffwp,DOESNT_PRESERVE_PATH))
(POLICY(fwfs,DOESNT_PRESERVE_PATH))
(POLICY(lfs,DOESNT_PRESERVE_PATH))
(POLICY(mfs,DOESNT_PRESERVE_PATH))
(POLICY(newest,DOESNT_PRESERVE_PATH))
@@ -51,16 +45,10 @@ namespace mergerfs
CONST_POLICY(invalid);
CONST_POLICY(all);
CONST_POLICY(einval);
CONST_POLICY(enosys);
CONST_POLICY(enotsup);
CONST_POLICY(eplfs);
CONST_POLICY(epmfs);
CONST_POLICY(erofs);
CONST_POLICY(exdev);
CONST_POLICY(ff);
CONST_POLICY(ffwp);
CONST_POLICY(fwfs);
CONST_POLICY(lfs);
CONST_POLICY(mfs);
CONST_POLICY(newest);
+3 -19
View File
@@ -28,6 +28,8 @@
#define POLICY_FAIL -1
#define POLICY_SUCCEEDED(RV) ((RV) == POLICY_SUCCESS)
#define POLICY_FAILED(RV) ((RV) == POLICY_FAIL)
#define POLICY_FAIL_ERRNO(ERRNO) (errno=ERRNO,POLICY_FAIL)
#define POLICY_FAIL_ENOENT POLICY_FAIL_ERRNO(ENOENT)
namespace mergerfs
{
@@ -41,16 +43,10 @@ namespace mergerfs
invalid = -1,
BEGIN = 0,
all = BEGIN,
einval,
enosys,
enotsup,
eplfs,
epmfs,
erofs,
exdev,
ff,
ffwp,
fwfs,
lfs,
mfs,
newest,
@@ -97,18 +93,12 @@ 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 einval(CType,cstrvec&,const char*,csize_t,cstrptrvec&);
static int enosys(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int enotsup(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 exdev(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int ff(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int ffwp(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int fwfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int invalid(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&);
@@ -176,16 +166,10 @@ namespace mergerfs
static const Policy &invalid;
static const Policy &all;
static const Policy &einval;
static const Policy &enosys;
static const Policy &enotsup;
static const Policy &eplfs;
static const Policy &epmfs;
static const Policy &erofs;
static const Policy &exdev;
static const Policy &ff;
static const Policy &ffwp;
static const Policy &fwfs;
static const Policy &lfs;
static const Policy &mfs;
static const Policy &newest;
+40 -16
View File
@@ -14,17 +14,14 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
@@ -32,12 +29,38 @@ using std::size_t;
static
int
_all(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
_all_create(const vector<string> &basepaths,
const size_t minfreespace,
vector<const string*> &paths)
{
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
}
if(paths.empty())
return POLICY_FAIL_ENOENT;
return POLICY_SUCCESS;
}
static
int
_all_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
int rv;
struct stat st;
string fullpath;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
@@ -46,13 +69,14 @@ _all(const vector<string> &basepaths,
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(LSTAT_SUCCEEDED(rv))
paths.push_back(basepath);
if(!fs::exists(fullpath))
continue;
paths.push_back(basepath);
}
if(paths.empty())
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
return POLICY_SUCCESS;
}
@@ -66,9 +90,9 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
const char *fp =
((type == Category::Enum::create) ? "" : fusepath);
if(type == Category::Enum::create)
return _all_create(basepaths,minfreespace,paths);
return _all(basepaths,fp,paths);
return _all_other(basepaths,fusepath,paths);
}
}
-38
View File
@@ -1,38 +0,0 @@
/*
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 "policy.hpp"
using std::string;
using std::vector;
namespace mergerfs
{
int
Policy::Func::enosys(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
return (errno=ENOSYS,POLICY_FAIL);
}
}
-38
View File
@@ -1,38 +0,0 @@
/*
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 "policy.hpp"
using std::string;
using std::vector;
namespace mergerfs
{
int
Policy::Func::enotsup(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
return (errno=ENOTSUP,POLICY_FAIL);
}
}
+83 -47
View File
@@ -15,76 +15,114 @@
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <limits>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
typedef struct statvfs statvfs_t;
static
void
_calc_lfs(const statvfs_t &fsstats,
const string *basepath,
const size_t minfreespace,
fsblkcnt_t &lfs,
const string *&lfsbasepath)
int
_eplfs_create(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
fsblkcnt_t spaceavail;
string fullpath;
size_t eplfs;
const string *eplfsbasepath;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) && (spaceavail < lfs))
eplfs = std::numeric_limits<size_t>::max();
eplfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
lfs = spaceavail;
lfsbasepath = basepath;
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceavail > eplfs)
continue;
eplfs = spaceavail;
eplfsbasepath = basepath;
}
if(eplfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(eplfsbasepath);
return POLICY_SUCCESS;
}
static
int
_eplfs(const Category::Enum::Type type,
_eplfs_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
size_t eplfs;
const string *eplfsbasepath;
eplfs = std::numeric_limits<size_t>::max();
eplfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceavail(*basepath,spaceavail))
continue;
if(spaceavail > eplfs)
continue;
eplfs = spaceavail;
eplfsbasepath = basepath;
}
if(eplfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(eplfsbasepath);
return POLICY_SUCCESS;
}
static
int
_eplfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
int rv;
string fullpath;
statvfs_t fsstats;
fsblkcnt_t eplfs;
const string *eplfsbasepath;
if(type == Category::Enum::create)
return _eplfs_create(basepaths,fusepath,minfreespace,paths);
eplfs = -1;
eplfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(STATVFS_SUCCEEDED(rv))
_calc_lfs(fsstats,basepath,minfreespace,eplfs,eplfsbasepath);
}
if(eplfsbasepath == NULL)
return (errno=ENOENT,POLICY_FAIL);
paths.push_back(eplfsbasepath);
return POLICY_SUCCESS;
return _eplfs_other(basepaths,fusepath,paths);
}
namespace mergerfs
@@ -94,13 +132,11 @@ namespace mergerfs
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
vector<const string*> &paths)
{
int rv;
const size_t minfs =
((type == Category::Enum::create) ? minfreespace : 0);
rv = _eplfs(type,basepaths,fusepath,minfs,paths);
rv = _eplfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::lfs(type,basepaths,fusepath,minfreespace,paths);
+69 -32
View File
@@ -15,77 +15,116 @@
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <limits>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
typedef struct statvfs statvfs_t;
static
void
_calc_mfs(const statvfs_t &fsstats,
const string *basepath,
const size_t minfreespace,
fsblkcnt_t &mfs,
const string *&mfsbasepath)
int
_epmfs_create(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
fsblkcnt_t spaceavail;
string fullpath;
size_t epmfs;
const string *epmfsbasepath;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) && (spaceavail > mfs))
epmfs = std::numeric_limits<size_t>::min();
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
mfs = spaceavail;
mfsbasepath = basepath;
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceavail < epmfs)
continue;
epmfs = spaceavail;
epmfsbasepath = basepath;
}
if(epmfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(epmfsbasepath);
return POLICY_SUCCESS;
}
static
int
_epmfs(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
_epmfs_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
int rv;
string fullpath;
statvfs_t fsstats;
fsblkcnt_t epmfs;
size_t epmfs;
const string *epmfsbasepath;
epmfs = 0;
epmfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(STATVFS_SUCCEEDED(rv))
_calc_mfs(fsstats,basepath,minfreespace,epmfs,epmfsbasepath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceavail(*basepath,spaceavail))
continue;
if(spaceavail < epmfs)
continue;
epmfs = spaceavail;
epmfsbasepath = basepath;
}
if(epmfsbasepath == NULL)
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
paths.push_back(epmfsbasepath);
return POLICY_SUCCESS;
}
static
int
_epmfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _epmfs_create(basepaths,fusepath,minfreespace,paths);
return _epmfs_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
@@ -96,10 +135,8 @@ namespace mergerfs
vector<const string*> &paths)
{
int rv;
const size_t minfs =
((type == Category::Enum::create) ? minfreespace : 0);
rv = _epmfs(basepaths,fusepath,minfs,paths);
rv = _epmfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
+1 -1
View File
@@ -33,6 +33,6 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
return (errno=EROFS,POLICY_FAIL);
return POLICY_FAIL_ERRNO(EROFS);
}
}
-38
View File
@@ -1,38 +0,0 @@
/*
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 "policy.hpp"
using std::string;
using std::vector;
namespace mergerfs
{
int
Policy::Func::exdev(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
return (errno=EXDEV,POLICY_FAIL);
}
}
+49 -18
View File
@@ -14,17 +14,14 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
@@ -32,22 +29,26 @@ using std::size_t;
static
int
_ff(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
_ff_create(const vector<string> &basepaths,
const size_t minfreespace,
vector<const string*> &paths)
{
int rv;
string fullpath;
struct stat st;
const string *fallback;
fallback = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(LSTAT_FAILED(rv))
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(fallback == NULL)
fallback = basepath;
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
@@ -55,7 +56,37 @@ _ff(const vector<string> &basepaths,
return POLICY_SUCCESS;
}
return (errno=ENOENT,POLICY_FAIL);
if(fallback == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(fallback);
return POLICY_SUCCESS;
}
static
int
_ff_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;
}
namespace mergerfs
@@ -67,9 +98,9 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
const char *fp =
((type == Category::Enum::create) ? "" : fusepath);
if(type == Category::Enum::create)
return _ff_create(basepaths,minfreespace,paths);
return _ff(basepaths,fp,paths);
return _ff_other(basepaths,fusepath,paths);
}
}
-82
View File
@@ -1,82 +0,0 @@
/*
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/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
static
int
_ffwp(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
int rv;
struct stat st;
string fullpath;
const string *fallback;
fallback = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(LSTAT_SUCCEEDED(rv))
{
paths.push_back(basepath);
return POLICY_SUCCESS;
}
else if(errno == EACCES)
{
fallback = basepath;
}
}
if(fallback == NULL)
return (errno=ENOENT,POLICY_FAIL);
paths.push_back(fallback);
return POLICY_SUCCESS;
}
namespace mergerfs
{
int
Policy::Func::ffwp(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
return _ffwp(basepaths,fusepath,paths);
}
}
-87
View File
@@ -1,87 +0,0 @@
/*
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/statvfs.h>
#include <errno.h>
#include <string>
#include <vector>
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
static
int
_fwfs(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
int rv;
string fullpath;
struct statvfs fsstats;
for(size_t i = 0, size = basepaths.size(); i != size; i++)
{
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(STATVFS_SUCCEEDED(rv))
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail < minfreespace)
continue;
paths.push_back(basepath);
return POLICY_SUCCESS;
}
}
return (errno=ENOENT,POLICY_FAIL);
}
namespace mergerfs
{
int
Policy::Func::fwfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
int rv;
const char *fp =
((type == Category::Enum::create) ? "" : fusepath);
rv = _fwfs(basepaths,fp,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
return rv;
}
}
+1 -1
View File
@@ -34,6 +34,6 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
return (errno=EINVAL,POLICY_FAIL);
return POLICY_FAIL_ERRNO(EINVAL);
}
}
+74 -40
View File
@@ -14,77 +14,113 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <unistd.h>
#include <errno.h>
#include <limits>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
using mergerfs::Policy;
using mergerfs::Category;
static
void
_calc_lfs(const struct statvfs &fsstats,
const string *basepath,
const size_t minfreespace,
fsblkcnt_t &lfs,
const string *&lfsbasepath)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) && (spaceavail < lfs))
{
lfs = spaceavail;
lfsbasepath = basepath;
}
}
static
int
_lfs(const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
_lfs_create(const vector<string> &basepaths,
const size_t minfreespace,
vector<const string*> &paths)
{
int rv;
string fullpath;
struct statvfs fsstats;
fsblkcnt_t lfs;
size_t lfs;
const string *lfsbasepath;
lfs = -1;
lfs = std::numeric_limits<size_t>::max();
lfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(spaceavail < minfreespace)
continue;
if(spaceavail > lfs)
continue;
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(STATVFS_SUCCEEDED(rv))
_calc_lfs(fsstats,basepath,minfreespace,lfs,lfsbasepath);
lfs = spaceavail;
lfsbasepath = basepath;
}
if(lfsbasepath == NULL)
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
paths.push_back(lfsbasepath);
return POLICY_SUCCESS;
}
static
int
_lfs_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
size_t lfs;
const string *lfsbasepath;
lfs = std::numeric_limits<size_t>::max();
lfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceavail(*basepath,spaceavail))
continue;
if(spaceavail > lfs)
continue;
lfs = spaceavail;
lfsbasepath = basepath;
}
if(lfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(lfsbasepath);
return POLICY_SUCCESS;
}
static
int
_lfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _lfs_create(basepaths,minfreespace,paths);
return _lfs_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
@@ -95,10 +131,8 @@ namespace mergerfs
vector<const string*> &paths)
{
int rv;
const char *fp =
((type == Category::Enum::create) ? "" : fusepath);
rv = _lfs(basepaths,fp,minfreespace,paths);
rv = _lfs(type,basepaths,fusepath,minfreespace,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
+73 -33
View File
@@ -14,70 +14,107 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/statvfs.h>
#include <errno.h>
#include <string>
#include <vector>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
using std::size_t;
static
void
_calc_mfs(const struct statvfs &fsstats,
const string *basepath,
fsblkcnt_t &mfs,
const string *&mfsbasepath)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if(spaceavail > mfs)
{
mfs = spaceavail;
mfsbasepath = basepath;
}
}
using mergerfs::Category;
static
int
_mfs(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
_mfs_create(const vector<string> &basepaths,
vector<const string*> &paths)
{
int rv;
string fullpath;
struct statvfs fsstats;
fsblkcnt_t mfs;
size_t mfs;
const string *mfsbasepath;
mfs = 0;
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
bool readonly;
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::info(*basepath,readonly,spaceavail))
continue;
if(readonly)
continue;
if(spaceavail < mfs)
continue;
rv = ::statvfs(fullpath.c_str(),&fsstats);
if(STATVFS_SUCCEEDED(rv))
_calc_mfs(fsstats,basepath,mfs,mfsbasepath);
mfs = spaceavail;
mfsbasepath = basepath;
}
if(mfsbasepath == NULL)
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
paths.push_back(mfsbasepath);
return POLICY_SUCCESS;
}
static
int
_mfs_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
string fullpath;
size_t mfs;
const string *mfsbasepath;
mfs = 0;
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath))
continue;
if(!fs::spaceavail(*basepath,spaceavail))
continue;
if(spaceavail < mfs)
continue;
mfs = spaceavail;
mfsbasepath = basepath;
}
if(mfsbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(mfsbasepath);
return POLICY_SUCCESS;
}
static
int
_mfs(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
if(type == Category::Enum::create)
return _mfs_create(basepaths,paths);
return _mfs_other(basepaths,fusepath,paths);
}
namespace mergerfs
{
int
@@ -87,9 +124,12 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
const char *fp =
((type == Category::Enum::create) ? "" : fusepath);
int rv;
return _mfs(basepaths,fp,paths);
rv = _mfs(type,basepaths,fusepath,paths);
if(POLICY_FAILED(rv))
rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths);
return rv;
}
}
+58 -17
View File
@@ -14,15 +14,14 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <string>
#include <vector>
#include <limits>
#include "fs.hpp"
#include "fs_path.hpp"
#include "policy.hpp"
#include "success_fail.hpp"
@@ -33,34 +32,73 @@ using std::size_t;
static
int
_newest(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
_newest_create(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
int rv;
struct stat st;
string fullpath;
time_t newest;
string fullpath;
const string *newestbasepath;
newest = std::numeric_limits<time_t>::min();
newestbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
struct stat st;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
if(LSTAT_SUCCEEDED(rv) && (st.st_mtime >= newest))
{
newest = st.st_mtime;
newestbasepath = basepath;
}
if(!fs::exists(fullpath,st))
continue;
if(st.st_mtime < newest)
continue;
if(fs::readonly(*basepath))
continue;
newest = st.st_mtime;
newestbasepath = basepath;
}
if(newestbasepath == NULL)
return (errno=ENOENT,POLICY_FAIL);
return POLICY_FAIL_ENOENT;
paths.push_back(newestbasepath);
return POLICY_SUCCESS;
}
static
int
_newest_other(const vector<string> &basepaths,
const char *fusepath,
vector<const string*> &paths)
{
time_t newest;
string fullpath;
const string *newestbasepath;
newest = std::numeric_limits<time_t>::min();
newestbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
struct stat st;
const string *basepath = &basepaths[i];
fs::path::make(basepath,fusepath,fullpath);
if(!fs::exists(fullpath,st))
continue;
if(st.st_mtime < newest)
continue;
newest = st.st_mtime;
newestbasepath = basepath;
}
if(newestbasepath == NULL)
return POLICY_FAIL_ENOENT;
paths.push_back(newestbasepath);
@@ -76,6 +114,9 @@ namespace mergerfs
const size_t minfreespace,
vector<const string*> &paths)
{
return _newest(basepaths,fusepath,paths);
if(type == Category::Enum::create)
return _newest_create(basepaths,fusepath,paths);
return _newest_other(basepaths,fusepath,paths);
}
}
+43 -31
View File
@@ -28,6 +28,7 @@
#include "fs_path.hpp"
#include "rv.hpp"
#include "rwlock.hpp"
#include "success_fail.hpp"
#include "ugid.hpp"
using std::string;
@@ -89,7 +90,7 @@ _rename_create_path_core(const vector<const string*> &oldbasepaths,
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
error = calc_error(rv,error,errno);
if(rv == -1)
if(RENAME_FAILED(rv))
tounlink.push_back(oldfullpath);
}
else
@@ -114,16 +115,16 @@ _rename_create_path(Policy::Func::Search searchFunc,
vector<const string*> oldbasepaths;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(rv == -1)
if(POLICY_FAILED(rv))
return -errno;
string newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath);
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
if(rv == -1)
if(POLICY_FAILED(rv))
return -errno;
error = -1;
error = RENAME_FAIL;
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
const string &oldbasepath = srcmounts[i];
@@ -135,12 +136,35 @@ _rename_create_path(Policy::Func::Search searchFunc,
error,toremove);
}
if(error == 0)
if(RENAME_SUCCEEDED(error))
_remove(toremove);
return -error;
}
static
int
_clonepath(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const string &dstbasepath,
const string &fusedirpath)
{
int rv;
vector<const string*> srcbasepath;
rv = searchFunc(srcmounts,fusedirpath.c_str(),minfreespace,srcbasepath);
if(POLICY_FAILED(rv))
return rv;
{
const ugid::SetRootGuard ugidGuard;
fs::clonepath(*srcbasepath[0],dstbasepath,fusedirpath.c_str());
}
return POLICY_SUCCESS;
}
static
int
_clonepath_if_would_create(Policy::Func::Search searchFunc,
@@ -158,25 +182,13 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
newfusedirpath = newfusepath;
fs::path::dirname(newfusedirpath);
rv = createFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
if(rv != -1)
{
if(oldbasepath == *newbasepath[0])
{
rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath);
if(rv != -1)
{
const ugid::SetRootGuard ugidGuard;
fs::clonepath(*newbasepath[0],oldbasepath,newfusedirpath.c_str());
}
}
else
{
rv = -1;
errno = EXDEV;
}
}
if(POLICY_FAILED(rv))
return rv;
return rv;
if(oldbasepath == *newbasepath[0])
return _clonepath(searchFunc,srcmounts,minfreespace,oldbasepath,newfusedirpath);
return POLICY_FAIL_ERRNO(EXDEV);
}
static
@@ -206,17 +218,17 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc,
fs::path::make(&oldbasepath,oldfusepath,oldfullpath);
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
if((rv == -1) && (errno == ENOENT))
if(RENAME_FAILED_WITH(rv,ENOENT))
{
rv = _clonepath_if_would_create(searchFunc,createFunc,
srcmounts,minfreespace,
oldbasepath,oldfusepath,newfusepath);
if(rv != -1)
if(POLICY_SUCCEEDED(rv))
rv = ::rename(oldfullpath.c_str(),newfullpath.c_str());
}
error = calc_error(rv,error,errno);
if(rv == -1)
if(RENAME_FAILED(rv))
toremove.push_back(oldfullpath);
}
else
@@ -241,10 +253,10 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
vector<const string*> oldbasepaths;
rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths);
if(rv == -1)
if(POLICY_FAILED(rv))
return -errno;
error = -1;
error = RENAME_FAIL;
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
const string &oldbasepath = srcmounts[i];
@@ -256,7 +268,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
error,toremove);
}
if(error == 0)
if(RENAME_SUCCEEDED(error))
_remove(toremove);
return -error;
@@ -284,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,
+31 -14
View File
@@ -14,25 +14,42 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <sys/statvfs.h>
#include <string>
#include <vector>
#include "policy.hpp"
#include "success_fail.hpp"
using std::string;
using std::vector;
namespace mergerfs
namespace StatVFS
{
int
Policy::Func::einval(const Category::Enum::Type type,
const vector<string> &basepaths,
const char *fusepath,
const size_t minfreespace,
vector<const string*> &paths)
static
inline
bool
readonly(const struct statvfs &st)
{
return (errno=EINVAL,POLICY_FAIL);
return (st.f_flag & ST_RDONLY);
}
static
inline
bool
readonly(const std::string &path)
{
int rv;
struct statvfs st;
rv = ::statvfs(path.c_str(),&st);
if(STATVFS_FAILED(rv))
return false;
return readonly(st);
}
static
inline
fsblkcnt_t
spaceavail(const struct statvfs &st)
{
return (st.f_frsize * st.f_bavail);
}
}
+11
View File
@@ -31,4 +31,15 @@
#define LSTAT_FAIL -1
#define LSTAT_FAILED(RV) ((RV) == LSTAT_FAIL)
#define FSTAT_SUCCESS 0
#define FSTAT_SUCCEEDED(RV) ((RV) == FSTAT_SUCCESS)
#define FSTAT_FAIL -1
#define FSTAT_FAILED(RV) ((RV) == FSTAT_FAIL)
#define RENAME_SUCCESS 0
#define RENAME_SUCCEEDED(RV) ((RV) == RENAME_SUCCESS)
#define RENAME_FAIL -1
#define RENAME_FAILED(RV) ((RV) == RENAME_FAIL)
#define RENAME_FAILED_WITH(RV,ERRNO) (((RV) == RENAME_FAIL) && (errno == ERRNO))
#endif /*__MERGERFS_SUCCESS_FAIL_HPP__ */
+14 -4
View File
@@ -21,8 +21,10 @@ import argparse
def git_tags():
args = ["git", "tag", '-l']
tags = subprocess.check_output(args)
tags = tags.split()
tags = [[int(X) for X in tag.split(".")] for tag in tags.split()]
tags.sort()
tags.reverse()
tags = [".".join([str(X) for X in tag]) for tag in tags]
return tags
def git_log(fromtag,totag):
@@ -95,9 +97,10 @@ def main():
if args.codename == '::guess::':
args.codename = guess_codename()
versuffix = "~"+args.distro+"-"+args.codename
if args.version == '::guess::':
ver = git_version()
args.version = ver+"~"+args.distro+"-"+args.codename
args.version = git_version()
tags = git_tags()
@@ -109,11 +112,18 @@ def main():
tags = zip(tags,tags)
tags.insert(0,(args.version,'HEAD'))
for i in xrange(0,len(tags)):
tags[i] = (tags[i][0] + versuffix,tags[i][1])
tag = tags[0]
for prev in tags[1:]:
lines = git_log(tag[1],prev[1])
if lines == ['']:
tag = prev
continue
print('%s (%s) %s; urgency=%s\n' % (args.name,tag[0],args.codename,args.urgency))
lines = git_log(tag[1],prev[1])
for line in lines:
print " * " + line