rfjakob/gocryptfs

prealloc failed: operation not supported

v03 opened this issue · 4 comments

v03 commented

When I try to setup encryption dir on the ZFS (ZoL 0.6.5.6-0ubuntu8 on ubuntu 16.04. gocryptfs is pulled from github using go get... and the latest commit is f035d3e) the files fail to be created.

Empty files work fine, but writing content to them fails.

$ gocryptfs -init foo                                                     ⏎
Choose a password for protecting your files.
Password: 
Repeat: 
The filesystem has been created successfully.

$ gocryptfs -debug -f foo bar
Debug output enabled
Password: 
Decrypting master key... 
done.

Now when I do touch bar/asdf it works fine. But trying to write something to it, using echo 1 > bar/asdf results in echo: write error: operation not supported and the following message in the gocryptfs running in foreground:

FS.GetAttr('asdf')
encryptPath 'asdf' -> './d2pkC2SxDZKpB2pWoii1sA==' (err: <nil>)
FS.GetAttr failed: 2=no such file or directory
encryptPath 'asdf' -> './d2pkC2SxDZKpB2pWoii1sA==' (err: <nil>)
getBackingPath: /home/123/foo + asdf -> /home/123/foo/d2pkC2SxDZKpB2pWoii1sA==
FS.GetAttr('asdf')
encryptPath 'asdf' -> './d2pkC2SxDZKpB2pWoii1sA==' (err: <nil>)
ino1068371: FUSE Write: offset=0 length=5
ino1068371: createHeader: prealloc failed: operation not supported

It doesn't matter what means of writing the file I use. cp, rsync etc all fail in the same way.

The very same version works if I put "foo" dir on tmpfs or ext4.

Apparently ZFS does not support fallocate ( openzfs/zfs#326 ). gocryptfs uses fallocate to allocate space before it uses it, to prevent running out of space in the middle of an operation, leaving a broken file behind.
I'm not sure how to handle this best.

v03 commented

Would it be possible to just check if we have enough space (+some to be safe)? At least under ZFS and simillar, to support it at all.

Ok I am checking now if fallocate is not supported at all. In this case, gocrypts will print a warning (only once) and continue working.

Now if the disk runs out of space while writing to a file, the incompletely written block (max 4kB) will be unreadable (it will report an I/O error if you try to read it). But you can still truncate or delete the file.

Ok I guess this is resolved. Closing the ticket.