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);
70 error = -zfs_create(dir, (char *)dentry->d_name.name,
71 vap, 0, mode, &ip, cr, 0, NULL);
75 d_instantiate(dentry, ip);
77 kmem_free(vap, sizeof(vattr_t));
79 ASSERT3S(error, <=, 0);
85 zpl_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
93 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
95 vap->va_mask = ATTR_MODE;
97 vap->va_uid = crgetfsuid(cr);
98 vap->va_gid = crgetfsgid(cr);
100 error = -zfs_create(dir, (char *)dentry->d_name.name,
101 vap, 0, mode, &ip, cr, 0, NULL);
105 d_instantiate(dentry, ip);
107 kmem_free(vap, sizeof(vattr_t));
109 ASSERT3S(error, <=, 0);
115 zpl_unlink(struct inode *dir, struct dentry *dentry)
121 error = -zfs_remove(dir, dname(dentry), cr);
123 ASSERT3S(error, <=, 0);
129 zpl_mkdir(struct inode *dir, struct dentry *dentry, int mode)
137 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
138 vap->va_mode = S_IFDIR | mode;
139 vap->va_mask = ATTR_MODE;
140 vap->va_uid = crgetfsuid(cr);
141 vap->va_gid = crgetfsgid(cr);
143 error = -zfs_mkdir(dir, dname(dentry), vap, &ip, cr, 0, NULL);
147 d_instantiate(dentry, ip);
149 kmem_free(vap, sizeof(vattr_t));
151 ASSERT3S(error, <=, 0);
157 zpl_rmdir(struct inode * dir, struct dentry *dentry)
163 error = -zfs_rmdir(dir, dname(dentry), NULL, cr, 0);
165 ASSERT3S(error, <=, 0);
171 zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
178 ip = dentry->d_inode;
180 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
182 error = -zfs_getattr(ip, vap, 0, cr);
186 stat->ino = ip->i_ino;
187 stat->dev = ip->i_sb->s_dev;
188 stat->mode = vap->va_mode;
189 stat->nlink = vap->va_nlink;
190 stat->uid = vap->va_uid;
191 stat->gid = vap->va_gid;
192 stat->rdev = vap->va_rdev;
193 stat->size = vap->va_size;
194 stat->atime = vap->va_atime;
195 stat->mtime = vap->va_mtime;
196 stat->ctime = vap->va_ctime;
197 stat->blksize = vap->va_blksize;
198 stat->blocks = vap->va_nblocks;
200 kmem_free(vap, sizeof(vattr_t));
202 ASSERT3S(error, <=, 0);
208 zpl_setattr(struct dentry *dentry, struct iattr *ia)
214 error = inode_change_ok(dentry->d_inode, ia);
219 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
220 vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK;
221 vap->va_mode = ia->ia_mode;
222 vap->va_uid = ia->ia_uid;
223 vap->va_gid = ia->ia_gid;
224 vap->va_size = ia->ia_size;
225 vap->va_atime = ia->ia_atime;
226 vap->va_mtime = ia->ia_mtime;
227 vap->va_ctime = ia->ia_ctime;
229 error = -zfs_setattr(dentry->d_inode, vap, 0, cr);
231 kmem_free(vap, sizeof(vattr_t));
233 ASSERT3S(error, <=, 0);
239 zpl_rename(struct inode *sdip, struct dentry *sdentry,
240 struct inode *tdip, struct dentry *tdentry)
246 error = -zfs_rename(sdip, dname(sdentry), tdip, dname(tdentry), cr, 0);
248 ASSERT3S(error, <=, 0);
254 zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
262 vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
263 vap->va_mode = S_IFLNK | S_IRWXUGO;
264 vap->va_mask = ATTR_MODE;
265 vap->va_uid = crgetfsuid(cr);
266 vap->va_gid = crgetfsgid(cr);
268 error = -zfs_symlink(dir, dname(dentry), vap, (char *)name, &ip, cr, 0);
272 d_instantiate(dentry, ip);
274 kmem_free(vap, sizeof(vattr_t));
276 ASSERT3S(error, <=, 0);
282 zpl_follow_link(struct dentry *dentry, struct nameidata *nd)
285 struct inode *ip = dentry->d_inode;
293 iov.iov_len = MAXPATHLEN;
294 iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
298 uio.uio_resid = (MAXPATHLEN - 1);
299 uio.uio_segflg = UIO_SYSSPACE;
301 error = -zfs_readlink(ip, &uio, cr);
303 kmem_free(link, MAXPATHLEN);
304 nd_set_link(nd, ERR_PTR(error));
306 nd_set_link(nd, link);
314 zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
318 link = nd_get_link(nd);
320 kmem_free(link, MAXPATHLEN);
324 zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
327 struct inode *ip = old_dentry->d_inode;
330 if (ip->i_nlink >= ZFS_LINK_MAX)
334 ip->i_ctime = CURRENT_TIME_SEC;
335 igrab(ip); /* Use ihold() if available */
337 error = -zfs_link(dir, ip, dname(dentry), cr);
343 d_instantiate(dentry, ip);
346 ASSERT3S(error, <=, 0);
351 const struct inode_operations zpl_inode_operations = {
352 .create = zpl_create,
354 .unlink = zpl_unlink,
355 .symlink = zpl_symlink,
359 .rename = zpl_rename,
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,
368 const struct inode_operations zpl_dir_inode_operations = {
369 .create = zpl_create,
370 .lookup = zpl_lookup,
372 .unlink = zpl_unlink,
373 .symlink = zpl_symlink,
377 .rename = zpl_rename,
378 .setattr = zpl_setattr,
379 .getattr = zpl_getattr,
380 .setxattr = generic_setxattr,
381 .getxattr = generic_getxattr,
382 .removexattr = generic_removexattr,
383 .listxattr = zpl_xattr_list,
386 const struct inode_operations zpl_symlink_inode_operations = {
387 .readlink = generic_readlink,
388 .follow_link = zpl_follow_link,
389 .put_link = zpl_put_link,
392 const struct inode_operations zpl_special_inode_operations = {
393 .setattr = zpl_setattr,
394 .getattr = zpl_getattr,
395 .setxattr = generic_setxattr,
396 .getxattr = generic_getxattr,
397 .removexattr = generic_removexattr,
398 .listxattr = zpl_xattr_list,