nfs未分类的内容

点击这里在哔哩哔哩bilibili在线观看配套的教学视频

点击跳转到nfs课程所有目录

正在更新的内容都放到这篇文章中,等到有些知识点达到一定量时,会把这些知识点整理成专门的一章。

1 df命令

client会发送两个GETATTR请求,第一个GETATTR请求以下内容:

第二个GETATTR请求以下内容:

执行df命令后,再执行echo 3 > /proc/sys/vm/drop_caches后立刻执行df命令,不会执行到__nfs_revalidate_inode()

2 网络超时

systemctl stop nfs-server
stat /mnt/file

[100196.619028] nfs: server localhost not responding, still trying
[100216.521372] nfs: server localhost not responding, timed out

3 delegation

echo something > /mnt/file; echo 3 > /proc/sys/vm/drop_caches; cat > /mnt/file:

nfsd4_open
  nfsd4_process_open2
    nfs4_open_delegation
      nfs4_set_delegation
        alloc_init_deleg
          nfs4_alloc_stid
      nfs4_put_stid(&dp->dl_stid)

echo 3 > /proc/sys/vm/drop_caches:

nfsd4_delegreturn
  destroy_delegation
    destroy_unhashed_deleg
      nfs4_put_stid
  nfs4_put_stid

4 Procedures和Operations

4.1 NFSv2 Procedures

NFSv2的Procedures定义在include/uapi/linux/nfs2.h中的NFSPROC_NULL ~ NFSPROC_STATFS,编码解码函数定义在nfs_proceduresnfsd_procedures2

4.2 NFSv3 Procedures

NFSv3的Procedures定义在include/uapi/linux/nfs3.h中的NFS3PROC_NULL ~ NFS3PROC_COMMIT,编码解码函数定义在nfs3_proceduresnfsd_procedures3

4.3 NFSv4 Procedures和Operations

NFSv4的Procedures定义在include/linux/nfs4.h中的NFSPROC4_NULLNFSPROC4_COMPOUND,server编码解码函数定义在nfsd_procedures4

NFSv4 server详细的Operations定义在include/linux/nfs4.h中的enum nfs_opnum4,处理函数定义在nfsd4_ops,编码解码函数定义在nfsd4_enc_opsnfsd4_dec_ops

NFSv4 client详细的Operations定义在include/linux/nfs4.h中的NFSPROC4_CLNT_NULL ~ NFSPROC4_CLNT_READ_PLUS,编码解码函数定义在nfs4_procedures

4.4 反向通道Operations

NFSv4反向通道的Operations定义在include/linux/nfs4.h中的enum nfs_cb_opnum4(老版本内核还重复定义在fs/nfs/callback.h中的enum nfs4_callback_opnum,我已经提补丁移到公共头文件: NFSv4, NFSD: move enum nfs_cb_opnum4 to include/linux/nfs4.h),server在fs/nfsd/state.h中还定义了nfsd4_cb_op,编码解码函数定义在nfs4_cb_procedures。client的编码解码函数定义在callback_ops

5 exportfs

struct export_operations

6 文件句柄

                    1.  +------------+ 6.
                   +----|   client   |>>>>>>>>>>+
                   |    +------------+          | 
           hey man,|          ^               你好像在逗我
    can you tell me|          |额,你猜?
 whose inode is 12?|        5.|                 |         
                   |    +------------+          |   
                   +--->|   server   |<<<<<<<<<<+  
                        +------------+
                         |  ^    ^  |
                     2.1.|  |    |  |2.2.
               +---------+  |    |  +---------+
               |            |    |            |
       hey boy |       i know   i know too    |hey girl
   do you know?|            |    |            |do you know?
               v            |    |            v      
          +----------+ 4.1. |    |4.2.   +----------+ 
          | /dev/sda |------+    +-------| /dev/sdb |
          +----------+                   +----------+
               ^                              ^      
        i am 12|                              |i am 12
               |3.1.                      3.2.|
          +----------+                   +----------+
          |   file   |                   |   file   |
          +----------+                   +----------+

7 idmap

启用idmap:

echo N > /sys/module/nfsd/parameters/nfs4_disable_idmapping # server,默认为Y
echo N > /sys/module/nfs/parameters/nfs4_disable_idmapping # client,默认为Y

server端/etc/idmapd.conf文件配置:

[General]

Verbosity = 0
Pipefs-Directory = /run/rpc_pipefs
# set your own domain here, if it differs from FQDN minus hostname
# 修改成其他值,客户端nfs_map_name_to_uid和nfs_map_group_to_gid函数中的id不为0
Domain = localdomain

[Mapping]

Nobody-User = nobody
Nobody-Group = nogroup