12

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...

Celik
  • 2,311
  • 2
  • 32
  • 54
  • If you run that setfattr command as the owner of the file instead of root, do you get an error message? – Mark Plotnick Jul 08 '14 at 11:28
  • my owner is also root and it also gives the same error message. have you try this? what I want is possible or? – Celik Jul 08 '14 at 12:13
  • 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. – Mark Plotnick Jul 08 '14 at 12:22
  • I added something on update part, are there what u want? – Celik Jul 08 '14 at 12:43
  • 1
    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. – Mark Plotnick Jul 08 '14 at 14:42
  • 1
    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. – Mark Plotnick Jul 08 '14 at 20:30

5 Answers5

13

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.

fbarriga
  • 133
  • 1
  • 5
7

(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).

Community
  • 1
  • 1
Drew
  • 111
  • 1
  • 4
  • 1
    While this may answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Tom Aranda Dec 14 '17 at 03:04
  • 4
    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? – Drew Dec 15 '17 at 07:13
  • 3
    It looks like Linux 5.9 will finally support user extended attributes for NFS. Server PR: https://lkml.org/lkml/2020/8/9/137 , Client PR: https://lkml.org/lkml/2020/8/14/712 – corford Oct 05 '20 at 18:23
3

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'
  • What to do if the `user_xattr` is not supported by the `mount` tool? I could not get that point. – Mohammed Noureldin Oct 25 '22 at 19:46
  • 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. – Nathan Shearer Oct 28 '22 at 17:52
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.

  • 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. – AlvaroAV Feb 23 '15 at 08:39
  • which link @AlvaroAV? Can you share it? – Celik Oct 20 '15 at 10:51
  • 2
    NFS support for Extended file attributes (xattr) was added in Linux 5.9 (released 11 October 2020) – Erik Sjölund Dec 25 '20 at 14:44
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

GoodMirek
  • 215
  • 1
  • 10