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.
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.
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]
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
26 #include <sys/zfs_vfsops.h>
27 #include <sys/zfs_vnops.h>
32 static struct dentry *
33 zpl_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
40 error = -zfs_lookup(dir, dname(dentry), &ip, 0, cr, NULL, NULL);
41 ASSERT3S(error, <=, 0);
46 return d_splice_alias(NULL, dentry);
48 return ERR_PTR(error);
51 return d_splice_alias(ip, dentry);
55 zpl_create(struct inode *dir, struct dentry *dentry, int mode,
64 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
66 vap->va_mask = ATTR_MODE;
67 vap->va_uid = crgetfsuid(cr);
68 vap->va_gid = crgetfsgid(cr);
69 vap->va_dentry = dentry;
71 error = -zfs_create(dir, (char *)dentry->d_name.name,
72 vap, 0, mode, &ip, cr, 0, NULL);
73 kmem_free(vap, sizeof(vattr_t));
75 ASSERT3S(error, <=, 0);
81 zpl_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
89 * We currently expect Linux to supply rdev=0 for all sockets
90 * and fifos, but we want to know if this behavior ever changes.
92 if (S_ISSOCK(mode) || S_ISFIFO(mode))
96 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
98 vap->va_mask = ATTR_MODE;
100 vap->va_uid = crgetfsuid(cr);
101 vap->va_gid = crgetfsgid(cr);
102 vap->va_dentry = dentry;
104 error = -zfs_create(dir, (char *)dentry->d_name.name,
105 vap, 0, mode, &ip, cr, 0, NULL);
106 kmem_free(vap, sizeof(vattr_t));
108 ASSERT3S(error, <=, 0);
114 zpl_unlink(struct inode *dir, struct dentry *dentry)
120 error = -zfs_remove(dir, dname(dentry), cr);
122 ASSERT3S(error, <=, 0);
128 zpl_mkdir(struct inode *dir, struct dentry *dentry, int mode)
136 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
137 vap->va_mode = S_IFDIR | mode;
138 vap->va_mask = ATTR_MODE;
139 vap->va_uid = crgetfsuid(cr);
140 vap->va_gid = crgetfsgid(cr);
141 vap->va_dentry = dentry;
143 error = -zfs_mkdir(dir, dname(dentry), vap, &ip, cr, 0, NULL);
144 kmem_free(vap, sizeof(vattr_t));
146 ASSERT3S(error, <=, 0);
152 zpl_rmdir(struct inode * dir, struct dentry *dentry)
158 error = -zfs_rmdir(dir, dname(dentry), NULL, cr, 0);
160 ASSERT3S(error, <=, 0);
166 zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
170 error = -zfs_getattr_fast(dentry->d_inode, stat);
171 ASSERT3S(error, <=, 0);
177 zpl_setattr(struct dentry *dentry, struct iattr *ia)
183 error = inode_change_ok(dentry->d_inode, ia);
188 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
189 vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK;
190 vap->va_mode = ia->ia_mode;
191 vap->va_uid = ia->ia_uid;
192 vap->va_gid = ia->ia_gid;
193 vap->va_size = ia->ia_size;
194 vap->va_atime = ia->ia_atime;
195 vap->va_mtime = ia->ia_mtime;
196 vap->va_ctime = ia->ia_ctime;
198 error = -zfs_setattr(dentry->d_inode, vap, 0, cr);
200 kmem_free(vap, sizeof(vattr_t));
202 ASSERT3S(error, <=, 0);
208 zpl_rename(struct inode *sdip, struct dentry *sdentry,
209 struct inode *tdip, struct dentry *tdentry)
215 error = -zfs_rename(sdip, dname(sdentry), tdip, dname(tdentry), cr, 0);
217 ASSERT3S(error, <=, 0);
223 zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
231 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
232 vap->va_mode = S_IFLNK | S_IRWXUGO;
233 vap->va_mask = ATTR_MODE;
234 vap->va_uid = crgetfsuid(cr);
235 vap->va_gid = crgetfsgid(cr);
236 vap->va_dentry = dentry;
238 error = -zfs_symlink(dir, dname(dentry), vap, (char *)name, &ip, cr, 0);
239 kmem_free(vap, sizeof(vattr_t));
241 ASSERT3S(error, <=, 0);
247 zpl_follow_link(struct dentry *dentry, struct nameidata *nd)
250 struct inode *ip = dentry->d_inode;
258 iov.iov_len = MAXPATHLEN;
259 iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
263 uio.uio_resid = (MAXPATHLEN - 1);
264 uio.uio_segflg = UIO_SYSSPACE;
266 error = -zfs_readlink(ip, &uio, cr);
268 kmem_free(link, MAXPATHLEN);
269 nd_set_link(nd, ERR_PTR(error));
271 nd_set_link(nd, link);
279 zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
283 link = nd_get_link(nd);
285 kmem_free(link, MAXPATHLEN);
289 zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
292 struct inode *ip = old_dentry->d_inode;
295 if (ip->i_nlink >= ZFS_LINK_MAX)
299 ip->i_ctime = CURRENT_TIME_SEC;
300 igrab(ip); /* Use ihold() if available */
302 error = -zfs_link(dir, ip, dname(dentry), cr);
308 d_instantiate(dentry, ip);
311 ASSERT3S(error, <=, 0);
316 const struct inode_operations zpl_inode_operations = {
317 .create = zpl_create,
319 .unlink = zpl_unlink,
320 .symlink = zpl_symlink,
324 .rename = zpl_rename,
325 .setattr = zpl_setattr,
326 .getattr = zpl_getattr,
327 .setxattr = generic_setxattr,
328 .getxattr = generic_getxattr,
329 .removexattr = generic_removexattr,
330 .listxattr = zpl_xattr_list,
333 const struct inode_operations zpl_dir_inode_operations = {
334 .create = zpl_create,
335 .lookup = zpl_lookup,
337 .unlink = zpl_unlink,
338 .symlink = zpl_symlink,
342 .rename = zpl_rename,
343 .setattr = zpl_setattr,
344 .getattr = zpl_getattr,
345 .setxattr = generic_setxattr,
346 .getxattr = generic_getxattr,
347 .removexattr = generic_removexattr,
348 .listxattr = zpl_xattr_list,
351 const struct inode_operations zpl_symlink_inode_operations = {
352 .readlink = generic_readlink,
353 .follow_link = zpl_follow_link,
354 .put_link = zpl_put_link,
357 const struct inode_operations zpl_special_inode_operations = {
358 .setattr = zpl_setattr,
359 .getattr = zpl_getattr,
360 .setxattr = generic_setxattr,
361 .getxattr = generic_getxattr,
362 .removexattr = generic_removexattr,
363 .listxattr = zpl_xattr_list,