]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/exportfs.h
exportfs: add fid type
[mirror_ubuntu-zesty-kernel.git] / include / linux / exportfs.h
CommitLineData
a5694255
CH
1#ifndef LINUX_EXPORTFS_H
2#define LINUX_EXPORTFS_H 1
3
4#include <linux/types.h>
5
6struct dentry;
7struct super_block;
d37065cd 8struct vfsmount;
a5694255 9
6e91ea2b
CH
10/*
11 * The fileid_type identifies how the file within the filesystem is encoded.
12 * In theory this is freely set and parsed by the filesystem, but we try to
13 * stick to conventions so we can share some generic code and don't confuse
14 * sniffers like ethereal/wireshark.
15 *
16 * The filesystem must not use the value '0' or '0xff'.
17 */
18enum fid_type {
19 /*
20 * The root, or export point, of the filesystem.
21 * (Never actually passed down to the filesystem.
22 */
23 FILEID_ROOT = 0,
24
25 /*
26 * 32bit inode number, 32 bit generation number.
27 */
28 FILEID_INO32_GEN = 1,
29
30 /*
31 * 32bit inode number, 32 bit generation number,
32 * 32 bit parent directory inode number.
33 */
34 FILEID_INO32_GEN_PARENT = 2,
35};
36
37struct fid {
38 union {
39 struct {
40 u32 ino;
41 u32 gen;
42 u32 parent_ino;
43 u32 parent_gen;
44 } i32;
45 __u32 raw[6];
46 };
47};
a5694255
CH
48
49/**
50 * struct export_operations - for nfsd to communicate with file systems
51 * @decode_fh: decode a file handle fragment and return a &struct dentry
52 * @encode_fh: encode a file handle fragment from a dentry
53 * @get_name: find the name for a given inode in a given directory
54 * @get_parent: find the parent of a given directory
55 * @get_dentry: find a dentry for the inode given a file handle sub-fragment
56 * @find_exported_dentry:
57 * set by the exporting module to a standard helper function.
58 *
59 * Description:
60 * The export_operations structure provides a means for nfsd to communicate
61 * with a particular exported file system - particularly enabling nfsd and
62 * the filesystem to co-operate when dealing with file handles.
63 *
64 * export_operations contains two basic operation for dealing with file
65 * handles, decode_fh() and encode_fh(), and allows for some other
66 * operations to be defined which standard helper routines use to get
67 * specific information from the filesystem.
68 *
69 * nfsd encodes information use to determine which filesystem a filehandle
70 * applies to in the initial part of the file handle. The remainder, termed
71 * a file handle fragment, is controlled completely by the filesystem. The
72 * standard helper routines assume that this fragment will contain one or
73 * two sub-fragments, one which identifies the file, and one which may be
74 * used to identify the (a) directory containing the file.
75 *
76 * In some situations, nfsd needs to get a dentry which is connected into a
77 * specific part of the file tree. To allow for this, it passes the
78 * function acceptable() together with a @context which can be used to see
79 * if the dentry is acceptable. As there can be multiple dentrys for a
80 * given file, the filesystem should check each one for acceptability before
81 * looking for the next. As soon as an acceptable one is found, it should
82 * be returned.
83 *
84 * decode_fh:
85 * @decode_fh is given a &struct super_block (@sb), a file handle fragment
86 * (@fh, @fh_len) and an acceptability testing function (@acceptable,
87 * @context). It should return a &struct dentry which refers to the same
88 * file that the file handle fragment refers to, and which passes the
89 * acceptability test. If it cannot, it should return a %NULL pointer if
90 * the file was found but no acceptable &dentries were available, or a
91 * %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or
92 * %ENOMEM).
93 *
94 * encode_fh:
95 * @encode_fh should store in the file handle fragment @fh (using at most
96 * @max_len bytes) information that can be used by @decode_fh to recover the
97 * file refered to by the &struct dentry @de. If the @connectable flag is
98 * set, the encode_fh() should store sufficient information so that a good
99 * attempt can be made to find not only the file but also it's place in the
100 * filesystem. This typically means storing a reference to de->d_parent in
101 * the filehandle fragment. encode_fh() should return the number of bytes
102 * stored or a negative error code such as %-ENOSPC
103 *
104 * get_name:
105 * @get_name should find a name for the given @child in the given @parent
106 * directory. The name should be stored in the @name (with the
107 * understanding that it is already pointing to a a %NAME_MAX+1 sized
108 * buffer. get_name() should return %0 on success, a negative error code
109 * or error. @get_name will be called without @parent->i_mutex held.
110 *
111 * get_parent:
112 * @get_parent should find the parent directory for the given @child which
113 * is also a directory. In the event that it cannot be found, or storage
114 * space cannot be allocated, a %ERR_PTR should be returned.
115 *
116 * get_dentry:
117 * Given a &super_block (@sb) and a pointer to a file-system specific inode
118 * identifier, possibly an inode number, (@inump) get_dentry() should find
119 * the identified inode and return a dentry for that inode. Any suitable
120 * dentry can be returned including, if necessary, a new dentry created with
121 * d_alloc_root. The caller can then find any other extant dentrys by
122 * following the d_alias links. If a new dentry was created using
123 * d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry
124 * should be d_rehash()ed.
125 *
126 * If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code
127 * can be returned. The @inump will be whatever was passed to
128 * nfsd_find_fh_dentry() in either the @obj or @parent parameters.
129 *
130 * Locking rules:
131 * get_parent is called with child->d_inode->i_mutex down
132 * get_name is not (which is possibly inconsistent)
133 */
134
135struct export_operations {
136 struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh,
137 int fh_len, int fh_type,
138 int (*acceptable)(void *context, struct dentry *de),
139 void *context);
140 int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len,
141 int connectable);
142 int (*get_name)(struct dentry *parent, char *name,
143 struct dentry *child);
144 struct dentry * (*get_parent)(struct dentry *child);
145 struct dentry * (*get_dentry)(struct super_block *sb, void *inump);
146
147 /* This is set by the exporting module to a standard helper */
148 struct dentry * (*find_exported_dentry)(
149 struct super_block *sb, void *obj, void *parent,
150 int (*acceptable)(void *context, struct dentry *de),
151 void *context);
152};
153
154extern struct dentry *find_exported_dentry(struct super_block *sb, void *obj,
155 void *parent, int (*acceptable)(void *context, struct dentry *de),
156 void *context);
157
6e91ea2b
CH
158extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid,
159 int *max_len, int connectable);
160extern struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
d37065cd
CH
161 int fh_len, int fileid_type, int (*acceptable)(void *, struct dentry *),
162 void *context);
163
a5694255 164#endif /* LINUX_EXPORTFS_H */