How to use Extended File Attributes on NFS?
Asked Answered
W

5

13

I have an NFS_Server - NFS_Client system. My client is mounted to an NFS_Server directory. I want to change the attribute of NFS_Server directory's files via NFS_Client mounted directory by using Extended File Attributes (xattr).

When I tried to set an attribute from the client side, it gives the following answer:

root@ubuntu:/mnt/nfs/var/nfs# setfattr -n user.comment -v "some comment" test.txt setfattr: nfs.txt: Permission denied

My question is:

  • is it possible to use Extended File Attributes via NFS?

  • if possible, how can I do this?

UPDATE:

Server side:

$ more  /etc/exports file has:    
/var/nfs        192.168.56.123(rw,sync,no_subtree_check)

Client side:

$ root@ubuntu:/# mount -t nfs
192.168.56.130:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=192.168.56.130,clientaddr=192.168.56.123)

thank you...

Wivinah answered 8/7, 2014 at 10:27 Comment(6)
If you run that setfattr command as the owner of the file instead of root, do you get an error message?Elsewhere
my owner is also root and it also gives the same error message. have you try this? what I want is possible or?Wivinah
Can you include the export options you're using on the server and the mount options you're using on the client and the distro of the client and server? That will help us a lot.Elsewhere
I added something on update part, are there what u want?Wivinah
Do you do any NFS id mapping on the server? The configuration file for that is /etc/idmapd.conf. By default, an NFS server will translate root on the client to nobody on the server, which is why I think running setfattr as root might be getting a permission denied error.Elsewhere
I'm very sorry, I thought your problem was just due to ID mapping, but it is more than that. It looks like Ubuntu's kernel does not support user xattr's on NFS filesystems. If you change your export options to include no_root_squash, which will allow root on the NFS client to be root on a server, the setfattr error message will change from Permission denied to Operation not supported. mount will accept an acl option but not a user_xattr option for an NFS filesystem.Elsewhere
T
15

You can use fuse_xattrs (a fuse filesystem layer) to emulate extended attributes (xattrs) on NFS shares. Basically you have to do:

  1. mount the NFS share. e.g.: /mnt/shared_data
  2. mount the fuse xattr layer: $ fuse_xattrs /mnt/shared_data /mnt/shared_data_with_xattrs

Now all the files on /mnt/shared_data can be accessed on /mnt/shared_data_with_xattrs with xattrs support. The extended attributes will be stored on sidecar files. The extended attributes are not going to be stored on the server filesystem as extended attributes, they are going to be stored in sidecar files.

Sadly this is only a work-around.

disclaimer: I'm the author of fuse_xattrs.

Thermionics answered 22/5, 2017 at 1:49 Comment(2)
Can you please accept @loloiccl's pull requests? They look kinda important. github.com/fbarriga/fuse_xattrs/pullsMilkandwater
In my use case, the NFS server is a BSD that I don't have root on. So your client-only tool looks like it would work well for my cross-platform situation!Claar
S
8

(This article is old, but I came across this article when looking for this functionality, and it doesn't represent the current state.)

As others have mentioned, there is no support for extended attributes in NFS. However, there is significant interest in it, to the extent there is a proposed standard (RFC 8276).

Signory answered 14/12, 2017 at 2:58 Comment(3)
While this may answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Safety
I'm sorry, I don't know what you're looking for @TomAranda--I provide the link, the essential part of the answer is that there is no support for extended attributes in NFS. I also don't just have a link--the link is described as a proposed standard (the implication being that it's a proposed standard for the support of extended attributes). I even described the link with the RFC number in case the link rots, which seems really unlikely in this case. Can you elaborate?Signory
It looks like Linux 5.9 will finally support user extended attributes for NFS. Server PR: lkml.org/lkml/2020/8/9/137 , Client PR: lkml.org/lkml/2020/8/14/712Supertax
U
6

All that is needed is Linux kernel version 5.9 or newer on both the server and client, then mount with NFS version 4.2 or newer. Support for extended attributes is enabled automatically when both server and client support nfs 4.2.

I have kernel version 5.15.16 on both my server and client with nfs-utils-2.5.4-r3, and it is working for me:

NFS Server /etc/exports

/  192.168.0.42(rw,subtree_check,no_root_squash)

NFS Client /etc/fstab

192.168.0.42:/  /mnt/slowpc  nfs  noatime,nodiratime,noauto,hard,rsize=1048576,wsize=1048576,timeo=60,retrans=60  0 0

NFS Client

# mount | grep /mnt/slowpc
192.168.0.42:/ on /mnt/slowpc type nfs4 (rw,noatime,nodiratime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=60,retrans=60,sec=sys,local_lock=none)
# cd /mnt/slowpc/tmp
# touch file
# printf bar | attr -s foo file
Attribute "foo" set to a 3 byte value for file:
bar
# attr -l file
Attribute "foo" has a 3 byte value for file

NFS Server

# attr -l /tmp/file
Attribute "foo" has a 3 byte value for /tmp/file

At https://lwn.net/Articles/799185/ it is mentioned that the new mount option user_xattr is required. However the current nfs utilities do not support that option. Fortunately user_xattr is enabled automatically when possible.

# mount -o user_xattr /mnt/test
mount.nfs: an incorrect mount option was specified
# tail -n 1 /var/log/messages
Jan 30 02:51:08 utl01 kernel: nfs: Unknown parameter 'user_xattr'
Undersize answered 9/6, 2022 at 16:5 Comment(2)
What to do if the user_xattr is not supported by the mount tool? I could not get that point.Self
When I tested this the mount command did not have a user_xattr option, but extended attributes were automatically enabled when possible. You can test a mountpoint by creating a test file and using the attr command from above.Undersize
S
1

Extended attributes are not supported by nfs.There is no handler for user attributes in nfs kernel module.For more information read RFC for nfsv4.

Sacksen answered 22/2, 2015 at 20:23 Comment(3)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Hegemony
which link @AlvaroAV? Can you share it?Wivinah
NFS support for Extended file attributes (xattr) was added in Linux 5.9 (released 11 October 2020)Renfrew
U
1

The NFS code in Linux 5.9 has finally presented support for user extended attributes (user xattrs).

The NFS server updates for Linux 5.9 have support for user-extended attributes on NFS. This is the functionality outlined via IETF's RFC 8276 for handling of file-system extended attributes in NFSv4. "This feature allows extended attributes (hereinafter also referred to as xattrs) to be interrogated and manipulated using NFSv4 clients. Xattrs are provided by a file system to associate opaque metadata, not interpreted by the file system, with files and directories. Such support is present in many modern local file systems. New file attributes are provided to allow clients to query the server for xattr support, with that support consisting of new operations to get and set xattrs on file system objects."

Source: https://www.phoronix.com/scan.php?page=news_item&px=Linux-5.9-NFS-Server-User-Xattr

Uzia answered 9/6, 2021 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.