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_vap_init(vattr_t *vap, struct inode *dir, struct dentry *dentry,
56 mode_t mode, cred_t *cr)
58 vap->va_mask = ATTR_MODE;
60 vap->va_dentry = dentry;
61 vap->va_uid = crgetfsuid(cr);
63 if (dir && dir->i_mode & S_ISGID) {
64 vap->va_gid = dir->i_gid;
66 vap->va_mode |= S_ISGID;
68 vap->va_gid = crgetfsgid(cr);
73 zpl_create(struct inode *dir, struct dentry *dentry, int mode,
82 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
83 zpl_vap_init(vap, dir, dentry, mode, cr);
85 error = -zfs_create(dir, (char *)dentry->d_name.name,
86 vap, 0, mode, &ip, cr, 0, NULL);
87 kmem_free(vap, sizeof(vattr_t));
89 ASSERT3S(error, <=, 0);
95 zpl_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
103 * We currently expect Linux to supply rdev=0 for all sockets
104 * and fifos, but we want to know if this behavior ever changes.
106 if (S_ISSOCK(mode) || S_ISFIFO(mode))
110 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
111 zpl_vap_init(vap, dir, dentry, mode, cr);
114 error = -zfs_create(dir, (char *)dentry->d_name.name,
115 vap, 0, mode, &ip, cr, 0, NULL);
116 kmem_free(vap, sizeof(vattr_t));
118 ASSERT3S(error, <=, 0);
124 zpl_unlink(struct inode *dir, struct dentry *dentry)
130 error = -zfs_remove(dir, dname(dentry), cr);
132 ASSERT3S(error, <=, 0);
138 zpl_mkdir(struct inode *dir, struct dentry *dentry, int mode)
146 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
147 zpl_vap_init(vap, dir, dentry, mode | S_IFDIR, cr);
149 error = -zfs_mkdir(dir, dname(dentry), vap, &ip, cr, 0, NULL);
150 kmem_free(vap, sizeof(vattr_t));
152 ASSERT3S(error, <=, 0);
158 zpl_rmdir(struct inode * dir, struct dentry *dentry)
164 error = -zfs_rmdir(dir, dname(dentry), NULL, cr, 0);
166 ASSERT3S(error, <=, 0);
172 zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
176 error = -zfs_getattr_fast(dentry->d_inode, stat);
177 ASSERT3S(error, <=, 0);
183 zpl_setattr(struct dentry *dentry, struct iattr *ia)
189 error = inode_change_ok(dentry->d_inode, ia);
194 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
195 vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK;
196 vap->va_mode = ia->ia_mode;
197 vap->va_uid = ia->ia_uid;
198 vap->va_gid = ia->ia_gid;
199 vap->va_size = ia->ia_size;
200 vap->va_atime = ia->ia_atime;
201 vap->va_mtime = ia->ia_mtime;
202 vap->va_ctime = ia->ia_ctime;
204 error = -zfs_setattr(dentry->d_inode, vap, 0, cr);
206 kmem_free(vap, sizeof(vattr_t));
208 ASSERT3S(error, <=, 0);
214 zpl_rename(struct inode *sdip, struct dentry *sdentry,
215 struct inode *tdip, struct dentry *tdentry)
221 error = -zfs_rename(sdip, dname(sdentry), tdip, dname(tdentry), cr, 0);
223 ASSERT3S(error, <=, 0);
229 zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
237 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
238 zpl_vap_init(vap, dir, dentry, S_IFLNK | S_IRWXUGO, cr);
240 error = -zfs_symlink(dir, dname(dentry), vap, (char *)name, &ip, cr, 0);
241 kmem_free(vap, sizeof(vattr_t));
243 ASSERT3S(error, <=, 0);
249 zpl_follow_link(struct dentry *dentry, struct nameidata *nd)
252 struct inode *ip = dentry->d_inode;
260 iov.iov_len = MAXPATHLEN;
261 iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
265 uio.uio_resid = (MAXPATHLEN - 1);
266 uio.uio_segflg = UIO_SYSSPACE;
268 error = -zfs_readlink(ip, &uio, cr);
270 kmem_free(link, MAXPATHLEN);
271 nd_set_link(nd, ERR_PTR(error));
273 nd_set_link(nd, link);
281 zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
285 link = nd_get_link(nd);
287 kmem_free(link, MAXPATHLEN);
291 zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
294 struct inode *ip = old_dentry->d_inode;
297 if (ip->i_nlink >= ZFS_LINK_MAX)
301 ip->i_ctime = CURRENT_TIME_SEC;
302 igrab(ip); /* Use ihold() if available */
304 error = -zfs_link(dir, ip, dname(dentry), cr);
310 d_instantiate(dentry, ip);
313 ASSERT3S(error, <=, 0);
318 const struct inode_operations zpl_inode_operations = {
319 .create = zpl_create,
321 .unlink = zpl_unlink,
322 .symlink = zpl_symlink,
326 .rename = zpl_rename,
327 .setattr = zpl_setattr,
328 .getattr = zpl_getattr,
329 .setxattr = generic_setxattr,
330 .getxattr = generic_getxattr,
331 .removexattr = generic_removexattr,
332 .listxattr = zpl_xattr_list,
335 const struct inode_operations zpl_dir_inode_operations = {
336 .create = zpl_create,
337 .lookup = zpl_lookup,
339 .unlink = zpl_unlink,
340 .symlink = zpl_symlink,
344 .rename = zpl_rename,
345 .setattr = zpl_setattr,
346 .getattr = zpl_getattr,
347 .setxattr = generic_setxattr,
348 .getxattr = generic_getxattr,
349 .removexattr = generic_removexattr,
350 .listxattr = zpl_xattr_list,
353 const struct inode_operations zpl_symlink_inode_operations = {
354 .readlink = generic_readlink,
355 .follow_link = zpl_follow_link,
356 .put_link = zpl_put_link,
359 const struct inode_operations zpl_special_inode_operations = {
360 .setattr = zpl_setattr,
361 .getattr = zpl_getattr,
362 .setxattr = generic_setxattr,
363 .getxattr = generic_getxattr,
364 .removexattr = generic_removexattr,
365 .listxattr = zpl_xattr_list,