]>
Commit | Line | Data |
---|---|---|
055656d4 GB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
22 | * Copyright (c) 2011 Gunnar Beutner | |
393b44c7 | 23 | * Copyright (c) 2012 Cyril Plisko. All rights reserved. |
055656d4 GB |
24 | */ |
25 | ||
26 | ||
27 | #include <sys/zfs_vnops.h> | |
28 | #include <sys/zfs_znode.h> | |
ebe7e575 | 29 | #include <sys/zfs_ctldir.h> |
055656d4 GB |
30 | #include <sys/zpl.h> |
31 | ||
32 | ||
33 | static int | |
756c3e5a RY |
34 | #ifdef HAVE_ENCODE_FH_WITH_INODE |
35 | zpl_encode_fh(struct inode *ip, __u32 *fh, int *max_len, struct inode *parent) | |
36 | { | |
37 | #else | |
055656d4 GB |
38 | zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable) |
39 | { | |
02730c33 | 40 | /* CSTYLED */ |
055656d4 | 41 | struct inode *ip = dentry->d_inode; |
756c3e5a | 42 | #endif /* HAVE_ENCODE_FH_WITH_INODE */ |
7fad6290 | 43 | fstrans_cookie_t cookie; |
756c3e5a | 44 | fid_t *fid = (fid_t *)fh; |
055656d4 GB |
45 | int len_bytes, rc; |
46 | ||
47 | len_bytes = *max_len * sizeof (__u32); | |
48 | ||
49 | if (len_bytes < offsetof(fid_t, fid_data)) | |
d1d7e268 | 50 | return (255); |
055656d4 GB |
51 | |
52 | fid->fid_len = len_bytes - offsetof(fid_t, fid_data); | |
7fad6290 | 53 | cookie = spl_fstrans_mark(); |
055656d4 | 54 | |
ebe7e575 BB |
55 | if (zfsctl_is_node(ip)) |
56 | rc = zfsctl_fid(ip, fid); | |
57 | else | |
58 | rc = zfs_fid(ip, fid); | |
055656d4 | 59 | |
7fad6290 | 60 | spl_fstrans_unmark(cookie); |
055656d4 GB |
61 | len_bytes = offsetof(fid_t, fid_data) + fid->fid_len; |
62 | *max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32); | |
63 | ||
64 | return (rc == 0 ? FILEID_INO32_GEN : 255); | |
65 | } | |
66 | ||
67 | static struct dentry * | |
68 | zpl_dentry_obtain_alias(struct inode *ip) | |
69 | { | |
70 | struct dentry *result; | |
71 | ||
72 | #ifdef HAVE_D_OBTAIN_ALIAS | |
73 | result = d_obtain_alias(ip); | |
74 | #else | |
75 | result = d_alloc_anon(ip); | |
76 | ||
77 | if (result == NULL) { | |
78 | iput(ip); | |
79 | result = ERR_PTR(-ENOMEM); | |
80 | } | |
81 | #endif /* HAVE_D_OBTAIN_ALIAS */ | |
82 | ||
d1d7e268 | 83 | return (result); |
055656d4 GB |
84 | } |
85 | ||
86 | static struct dentry * | |
87 | zpl_fh_to_dentry(struct super_block *sb, struct fid *fh, | |
88 | int fh_len, int fh_type) | |
89 | { | |
055656d4 | 90 | fid_t *fid = (fid_t *)fh; |
7fad6290 | 91 | fstrans_cookie_t cookie; |
055656d4 GB |
92 | struct inode *ip; |
93 | int len_bytes, rc; | |
94 | ||
95 | len_bytes = fh_len * sizeof (__u32); | |
96 | ||
97 | if (fh_type != FILEID_INO32_GEN || | |
98 | len_bytes < offsetof(fid_t, fid_data) || | |
99 | len_bytes < offsetof(fid_t, fid_data) + fid->fid_len) | |
d1d7e268 | 100 | return (ERR_PTR(-EINVAL)); |
055656d4 | 101 | |
7fad6290 | 102 | cookie = spl_fstrans_mark(); |
2cf7f52b | 103 | rc = zfs_vget(sb, &ip, fid); |
7fad6290 | 104 | spl_fstrans_unmark(cookie); |
055656d4 | 105 | |
79065ed5 JS |
106 | if (rc) { |
107 | /* | |
108 | * If we see ENOENT it might mean that an NFSv4 * client | |
109 | * is using a cached inode value in a file handle and | |
110 | * that the sought after file has had its inode changed | |
111 | * by a third party. So change the error to ESTALE | |
112 | * which will trigger a full lookup by the client and | |
113 | * will find the new filename/inode pair if it still | |
114 | * exists. | |
115 | */ | |
116 | if (rc == ENOENT) | |
117 | rc = ESTALE; | |
118 | ||
d1d7e268 | 119 | return (ERR_PTR(-rc)); |
79065ed5 | 120 | } |
055656d4 GB |
121 | |
122 | ASSERT((ip != NULL) && !IS_ERR(ip)); | |
123 | ||
d1d7e268 | 124 | return (zpl_dentry_obtain_alias(ip)); |
055656d4 GB |
125 | } |
126 | ||
127 | static struct dentry * | |
128 | zpl_get_parent(struct dentry *child) | |
129 | { | |
130 | cred_t *cr = CRED(); | |
7fad6290 | 131 | fstrans_cookie_t cookie; |
055656d4 GB |
132 | struct inode *ip; |
133 | int error; | |
134 | ||
135 | crhold(cr); | |
7fad6290 | 136 | cookie = spl_fstrans_mark(); |
055656d4 | 137 | error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL); |
7fad6290 | 138 | spl_fstrans_unmark(cookie); |
055656d4 GB |
139 | crfree(cr); |
140 | ASSERT3S(error, <=, 0); | |
141 | ||
142 | if (error) | |
d1d7e268 | 143 | return (ERR_PTR(error)); |
055656d4 | 144 | |
d1d7e268 | 145 | return (zpl_dentry_obtain_alias(ip)); |
055656d4 GB |
146 | } |
147 | ||
393b44c7 CP |
148 | #ifdef HAVE_COMMIT_METADATA |
149 | static int | |
150 | zpl_commit_metadata(struct inode *inode) | |
151 | { | |
152 | cred_t *cr = CRED(); | |
7fad6290 | 153 | fstrans_cookie_t cookie; |
393b44c7 CP |
154 | int error; |
155 | ||
b23975cb AV |
156 | if (zfsctl_is_node(inode)) |
157 | return (0); | |
158 | ||
393b44c7 | 159 | crhold(cr); |
7fad6290 | 160 | cookie = spl_fstrans_mark(); |
393b44c7 | 161 | error = -zfs_fsync(inode, 0, cr); |
7fad6290 | 162 | spl_fstrans_unmark(cookie); |
393b44c7 CP |
163 | crfree(cr); |
164 | ASSERT3S(error, <=, 0); | |
165 | ||
d1d7e268 | 166 | return (error); |
393b44c7 CP |
167 | } |
168 | #endif /* HAVE_COMMIT_METADATA */ | |
169 | ||
055656d4 | 170 | const struct export_operations zpl_export_operations = { |
d1d7e268 MK |
171 | .encode_fh = zpl_encode_fh, |
172 | .fh_to_dentry = zpl_fh_to_dentry, | |
173 | .get_parent = zpl_get_parent, | |
393b44c7 | 174 | #ifdef HAVE_COMMIT_METADATA |
d1d7e268 | 175 | .commit_metadata = zpl_commit_metadata, |
393b44c7 | 176 | #endif /* HAVE_COMMIT_METADATA */ |
055656d4 | 177 | }; |