]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - zfs/module/zfs/zpl_export.c
UBUNTU: SAUCE: (noup) Update spl to 0.6.5.9-1, zfs to 0.6.5.9-2
[mirror_ubuntu-artful-kernel.git] / zfs / module / zfs / zpl_export.c
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
23 * Copyright (c) 2012 Cyril Plisko. All rights reserved.
24 */
25
26
27 #include <sys/zfs_vnops.h>
28 #include <sys/zfs_znode.h>
29 #include <sys/zfs_ctldir.h>
30 #include <sys/zpl.h>
31
32
33 static int
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
38 zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
39 {
40 struct inode *ip = dentry->d_inode;
41 #endif /* HAVE_ENCODE_FH_WITH_INODE */
42 fstrans_cookie_t cookie;
43 fid_t *fid = (fid_t *)fh;
44 int len_bytes, rc;
45
46 len_bytes = *max_len * sizeof (__u32);
47
48 if (len_bytes < offsetof(fid_t, fid_data))
49 return (255);
50
51 fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
52 cookie = spl_fstrans_mark();
53
54 if (zfsctl_is_node(ip))
55 rc = zfsctl_fid(ip, fid);
56 else
57 rc = zfs_fid(ip, fid);
58
59 spl_fstrans_unmark(cookie);
60 len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
61 *max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);
62
63 return (rc == 0 ? FILEID_INO32_GEN : 255);
64 }
65
66 static struct dentry *
67 zpl_dentry_obtain_alias(struct inode *ip)
68 {
69 struct dentry *result;
70
71 #ifdef HAVE_D_OBTAIN_ALIAS
72 result = d_obtain_alias(ip);
73 #else
74 result = d_alloc_anon(ip);
75
76 if (result == NULL) {
77 iput(ip);
78 result = ERR_PTR(-ENOMEM);
79 }
80 #endif /* HAVE_D_OBTAIN_ALIAS */
81
82 return (result);
83 }
84
85 static struct dentry *
86 zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
87 int fh_len, int fh_type)
88 {
89 fid_t *fid = (fid_t *)fh;
90 fstrans_cookie_t cookie;
91 struct inode *ip;
92 int len_bytes, rc;
93
94 len_bytes = fh_len * sizeof (__u32);
95
96 if (fh_type != FILEID_INO32_GEN ||
97 len_bytes < offsetof(fid_t, fid_data) ||
98 len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
99 return (ERR_PTR(-EINVAL));
100
101 cookie = spl_fstrans_mark();
102 rc = zfs_vget(sb, &ip, fid);
103 spl_fstrans_unmark(cookie);
104
105 if (rc) {
106 /*
107 * If we see ENOENT it might mean that an NFSv4 * client
108 * is using a cached inode value in a file handle and
109 * that the sought after file has had its inode changed
110 * by a third party. So change the error to ESTALE
111 * which will trigger a full lookup by the client and
112 * will find the new filename/inode pair if it still
113 * exists.
114 */
115 if (rc == ENOENT)
116 rc = ESTALE;
117
118 return (ERR_PTR(-rc));
119 }
120
121 ASSERT((ip != NULL) && !IS_ERR(ip));
122
123 return (zpl_dentry_obtain_alias(ip));
124 }
125
126 static struct dentry *
127 zpl_get_parent(struct dentry *child)
128 {
129 cred_t *cr = CRED();
130 fstrans_cookie_t cookie;
131 struct inode *ip;
132 int error;
133
134 crhold(cr);
135 cookie = spl_fstrans_mark();
136 error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL);
137 spl_fstrans_unmark(cookie);
138 crfree(cr);
139 ASSERT3S(error, <=, 0);
140
141 if (error)
142 return (ERR_PTR(error));
143
144 return (zpl_dentry_obtain_alias(ip));
145 }
146
147 #ifdef HAVE_COMMIT_METADATA
148 static int
149 zpl_commit_metadata(struct inode *inode)
150 {
151 cred_t *cr = CRED();
152 fstrans_cookie_t cookie;
153 int error;
154
155 if (zfsctl_is_node(inode))
156 return (0);
157
158 crhold(cr);
159 cookie = spl_fstrans_mark();
160 error = -zfs_fsync(inode, 0, cr);
161 spl_fstrans_unmark(cookie);
162 crfree(cr);
163 ASSERT3S(error, <=, 0);
164
165 return (error);
166 }
167 #endif /* HAVE_COMMIT_METADATA */
168
169 const struct export_operations zpl_export_operations = {
170 .encode_fh = zpl_encode_fh,
171 .fh_to_dentry = zpl_fh_to_dentry,
172 .get_parent = zpl_get_parent,
173 #ifdef HAVE_COMMIT_METADATA
174 .commit_metadata = zpl_commit_metadata,
175 #endif /* HAVE_COMMIT_METADATA */
176 };