Blame view
fs/xfs/xfs_export.c
5.87 KB
0b61f8a40 xfs: convert to S... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
1da177e4c Linux-2.6.12-rc2 |
2 |
/* |
7b7187698 [XFS] Update lice... |
3 4 |
* Copyright (c) 2004-2005 Silicon Graphics, Inc. * All Rights Reserved. |
1da177e4c Linux-2.6.12-rc2 |
5 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
6 |
#include "xfs.h" |
5467b34bd xfs: move xfs_ino... |
7 |
#include "xfs_shared.h" |
a4fbe6ab1 xfs: decouple ino... |
8 |
#include "xfs_format.h" |
239880ef6 xfs: decouple log... |
9 10 |
#include "xfs_log_format.h" #include "xfs_trans_resv.h" |
1da177e4c Linux-2.6.12-rc2 |
11 |
#include "xfs_mount.h" |
2b9ab5ab9 xfs: reshuffle di... |
12 |
#include "xfs_dir2.h" |
1da177e4c Linux-2.6.12-rc2 |
13 |
#include "xfs_export.h" |
739bfb2a7 [XFS] call common... |
14 |
#include "xfs_inode.h" |
239880ef6 xfs: decouple log... |
15 |
#include "xfs_trans.h" |
978ebd97d xfs_export_operat... |
16 |
#include "xfs_inode_item.h" |
33479e054 xfs: remove xfs_i... |
17 |
#include "xfs_icache.h" |
527851124 xfs: implement pN... |
18 |
#include "xfs_pnfs.h" |
1da177e4c Linux-2.6.12-rc2 |
19 20 |
/* |
c38344fe9 xfs: new export ops |
21 22 23 |
* Note that we only accept fileids which are long enough rather than allow * the parent generation number to default to zero. XFS considers zero a * valid generation number not an invalid/wildcard value. |
1da177e4c Linux-2.6.12-rc2 |
24 |
*/ |
c38344fe9 xfs: new export ops |
25 |
static int xfs_fileid_length(int fileid_type) |
1da177e4c Linux-2.6.12-rc2 |
26 |
{ |
c38344fe9 xfs: new export ops |
27 28 29 30 31 32 33 34 35 |
switch (fileid_type) { case FILEID_INO32_GEN: return 2; case FILEID_INO32_GEN_PARENT: return 4; case FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG: return 3; case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG: return 6; |
1da177e4c Linux-2.6.12-rc2 |
36 |
} |
94e07a759 fs: encode_fh: re... |
37 |
return FILEID_INVALID; |
1da177e4c Linux-2.6.12-rc2 |
38 |
} |
1da177e4c Linux-2.6.12-rc2 |
39 |
STATIC int |
a50cd2692 [XFS] Switch over... |
40 |
xfs_fs_encode_fh( |
b0b0382bb ->encode_fh() API... |
41 42 43 44 |
struct inode *inode, __u32 *fh, int *max_len, struct inode *parent) |
1da177e4c Linux-2.6.12-rc2 |
45 |
{ |
c38344fe9 xfs: new export ops |
46 47 |
struct fid *fid = (struct fid *)fh; struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fh; |
c38344fe9 xfs: new export ops |
48 |
int fileid_type; |
1da177e4c Linux-2.6.12-rc2 |
49 |
int len; |
1da177e4c Linux-2.6.12-rc2 |
50 51 |
/* Directories don't need their parent encoded, they have ".." */ |
b0b0382bb ->encode_fh() API... |
52 |
if (!parent) |
c38344fe9 xfs: new export ops |
53 54 55 |
fileid_type = FILEID_INO32_GEN; else fileid_type = FILEID_INO32_GEN_PARENT; |
576ecb8e2 xfs: fix exportin... |
56 |
/* |
b63da6c8d xfs: delete dupli... |
57 |
* If the filesystem may contain 64bit inode numbers, we need |
576ecb8e2 xfs: fix exportin... |
58 59 60 61 62 63 64 65 |
* to use larger file handles that can represent them. * * While we only allocate inodes that do not fit into 32 bits any * large enough filesystem may contain them, thus the slightly * confusing looking conditional below. */ if (!(XFS_M(inode->i_sb)->m_flags & XFS_MOUNT_SMALL_INUMS) || (XFS_M(inode->i_sb)->m_flags & XFS_MOUNT_32BITINODES)) |
c38344fe9 xfs: new export ops |
66 |
fileid_type |= XFS_FILEID_TYPE_64FLAG; |
1da177e4c Linux-2.6.12-rc2 |
67 68 69 70 71 72 73 |
/* * Only encode if there is enough space given. In practice * this means we can't export a filesystem with 64bit inodes * over NFSv2 with the subtree_check export option; the other * seven combinations work. The real answer is "don't use v2". */ |
c38344fe9 xfs: new export ops |
74 |
len = xfs_fileid_length(fileid_type); |
5fe0c2378 exportfs: Return ... |
75 76 |
if (*max_len < len) { *max_len = len; |
94e07a759 fs: encode_fh: re... |
77 |
return FILEID_INVALID; |
5fe0c2378 exportfs: Return ... |
78 |
} |
1da177e4c Linux-2.6.12-rc2 |
79 |
*max_len = len; |
c38344fe9 xfs: new export ops |
80 81 |
switch (fileid_type) { case FILEID_INO32_GEN_PARENT: |
b0b0382bb ->encode_fh() API... |
82 83 |
fid->i32.parent_ino = XFS_I(parent)->i_ino; fid->i32.parent_gen = parent->i_generation; |
c38344fe9 xfs: new export ops |
84 85 |
/*FALLTHRU*/ case FILEID_INO32_GEN: |
c29f7d457 xfs: fix nfs expo... |
86 |
fid->i32.ino = XFS_I(inode)->i_ino; |
c38344fe9 xfs: new export ops |
87 88 89 |
fid->i32.gen = inode->i_generation; break; case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG: |
b0b0382bb ->encode_fh() API... |
90 91 |
fid64->parent_ino = XFS_I(parent)->i_ino; fid64->parent_gen = parent->i_generation; |
c38344fe9 xfs: new export ops |
92 93 |
/*FALLTHRU*/ case FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG: |
c29f7d457 xfs: fix nfs expo... |
94 |
fid64->ino = XFS_I(inode)->i_ino; |
c38344fe9 xfs: new export ops |
95 96 |
fid64->gen = inode->i_generation; break; |
1da177e4c Linux-2.6.12-rc2 |
97 |
} |
c38344fe9 xfs: new export ops |
98 99 |
return fileid_type; |
1da177e4c Linux-2.6.12-rc2 |
100 |
} |
c38344fe9 xfs: new export ops |
101 102 |
STATIC struct inode * xfs_nfs_get_inode( |
1da177e4c Linux-2.6.12-rc2 |
103 |
struct super_block *sb, |
c38344fe9 xfs: new export ops |
104 105 |
u64 ino, u32 generation) |
447a5647c treewide: Align f... |
106 |
{ |
f71354bc3 [XFS] Cleanup var... |
107 108 |
xfs_mount_t *mp = XFS_M(sb); xfs_inode_t *ip; |
1da177e4c Linux-2.6.12-rc2 |
109 |
int error; |
f71354bc3 [XFS] Cleanup var... |
110 111 112 113 114 |
/* * NFS can sometimes send requests for ino 0. Fail them gracefully. */ if (ino == 0) return ERR_PTR(-ESTALE); |
1da177e4c Linux-2.6.12-rc2 |
115 |
|
c9a98553d [XFS] pass XFS_IG... |
116 |
/* |
1920779e6 xfs: rename XFS_I... |
117 118 119 |
* The XFS_IGET_UNTRUSTED means that an invalid inode number is just * fine and not an indication of a corrupted filesystem as clients can * send invalid file handles and we have to handle it gracefully.. |
c9a98553d [XFS] pass XFS_IG... |
120 |
*/ |
ef35e9255 xfs: remove xfs_i... |
121 |
error = xfs_iget(mp, NULL, ino, XFS_IGET_UNTRUSTED, 0, &ip); |
c9a98553d [XFS] pass XFS_IG... |
122 |
if (error) { |
29cad0b3e xfs: push corrupt... |
123 |
|
c9a98553d [XFS] pass XFS_IG... |
124 125 |
/* * EINVAL means the inode cluster doesn't exist anymore. |
29cad0b3e xfs: push corrupt... |
126 127 128 |
* EFSCORRUPTED means the metadata pointing to the inode cluster * or the inode cluster itself is corrupt. This implies the * filehandle is stale, so we should translate it here. |
c9a98553d [XFS] pass XFS_IG... |
129 130 131 |
* We don't use ESTALE directly down the chain to not * confuse applications using bulkstat that expect EINVAL. */ |
29cad0b3e xfs: push corrupt... |
132 133 134 135 |
switch (error) { case -EINVAL: case -ENOENT: case -EFSCORRUPTED: |
2451337dd xfs: global error... |
136 |
error = -ESTALE; |
29cad0b3e xfs: push corrupt... |
137 138 139 140 |
break; default: break; } |
2451337dd xfs: global error... |
141 |
return ERR_PTR(error); |
c9a98553d [XFS] pass XFS_IG... |
142 |
} |
f71354bc3 [XFS] Cleanup var... |
143 |
|
9e9a2674e xfs: move inode g... |
144 |
if (VFS_I(ip)->i_generation != generation) { |
44a8736bd xfs: clean up IRE... |
145 |
xfs_irele(ip); |
ad1a2c878 xfs: failure mapp... |
146 |
return ERR_PTR(-ESTALE); |
f71354bc3 [XFS] Cleanup var... |
147 |
} |
c38344fe9 xfs: new export ops |
148 |
|
016516462 [XFS] Avoid direc... |
149 |
return VFS_I(ip); |
c38344fe9 xfs: new export ops |
150 151 152 153 154 155 156 157 |
} STATIC struct dentry * xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fileid_type) { struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; struct inode *inode = NULL; |
c38344fe9 xfs: new export ops |
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
if (fh_len < xfs_fileid_length(fileid_type)) return NULL; switch (fileid_type) { case FILEID_INO32_GEN_PARENT: case FILEID_INO32_GEN: inode = xfs_nfs_get_inode(sb, fid->i32.ino, fid->i32.gen); break; case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG: case FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG: inode = xfs_nfs_get_inode(sb, fid64->ino, fid64->gen); break; } |
440037287 [PATCH] switch al... |
172 |
return d_obtain_alias(inode); |
c38344fe9 xfs: new export ops |
173 174 175 176 177 178 179 180 |
} STATIC struct dentry * xfs_fs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fileid_type) { struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; struct inode *inode = NULL; |
c38344fe9 xfs: new export ops |
181 |
|
35c2a7f49 tmpfs,ceph,gfs2,i... |
182 183 |
if (fh_len < xfs_fileid_length(fileid_type)) return NULL; |
c38344fe9 xfs: new export ops |
184 185 186 187 188 189 190 191 192 193 |
switch (fileid_type) { case FILEID_INO32_GEN_PARENT: inode = xfs_nfs_get_inode(sb, fid->i32.parent_ino, fid->i32.parent_gen); break; case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG: inode = xfs_nfs_get_inode(sb, fid64->parent_ino, fid64->parent_gen); break; } |
440037287 [PATCH] switch al... |
194 |
return d_obtain_alias(inode); |
1da177e4c Linux-2.6.12-rc2 |
195 196 197 |
} STATIC struct dentry * |
a50cd2692 [XFS] Switch over... |
198 |
xfs_fs_get_parent( |
1da177e4c Linux-2.6.12-rc2 |
199 200 201 |
struct dentry *child) { int error; |
ef1f5e7ad [XFS] cleanup vno... |
202 |
struct xfs_inode *cip; |
1da177e4c Linux-2.6.12-rc2 |
203 |
|
2b0143b5c VFS: normal files... |
204 |
error = xfs_lookup(XFS_I(d_inode(child)), &xfs_name_dotdot, &cip, NULL); |
1da177e4c Linux-2.6.12-rc2 |
205 |
if (unlikely(error)) |
2451337dd xfs: global error... |
206 |
return ERR_PTR(error); |
1da177e4c Linux-2.6.12-rc2 |
207 |
|
440037287 [PATCH] switch al... |
208 |
return d_obtain_alias(VFS_I(cip)); |
1da177e4c Linux-2.6.12-rc2 |
209 |
} |
978ebd97d xfs_export_operat... |
210 211 212 213 |
STATIC int xfs_fs_nfs_commit_metadata( struct inode *inode) { |
54fbdd103 xfs: factor out a... |
214 |
return xfs_log_force_inode(XFS_I(inode)); |
978ebd97d xfs_export_operat... |
215 |
} |
396551644 exportfs: make st... |
216 |
const struct export_operations xfs_export_operations = { |
a50cd2692 [XFS] Switch over... |
217 |
.encode_fh = xfs_fs_encode_fh, |
c38344fe9 xfs: new export ops |
218 219 |
.fh_to_dentry = xfs_fs_fh_to_dentry, .fh_to_parent = xfs_fs_fh_to_parent, |
a50cd2692 [XFS] Switch over... |
220 |
.get_parent = xfs_fs_get_parent, |
978ebd97d xfs_export_operat... |
221 |
.commit_metadata = xfs_fs_nfs_commit_metadata, |
15d66ac20 xfs: abstract blo... |
222 |
#ifdef CONFIG_EXPORTFS_BLOCK_OPS |
527851124 xfs: implement pN... |
223 224 225 226 |
.get_uuid = xfs_fs_get_uuid, .map_blocks = xfs_fs_map_blocks, .commit_blocks = xfs_fs_commit_blocks, #endif |
1da177e4c Linux-2.6.12-rc2 |
227 |
}; |