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 Gunnar Beutner
26 #include <sys/zfs_vnops.h>
27 #include <sys/zfs_znode.h>
28 #include <sys/zfs_ctldir.h>
33 zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
35 fid_t *fid = (fid_t *)fh;
36 struct inode *ip = dentry->d_inode;
39 len_bytes = *max_len * sizeof (__u32);
41 if (len_bytes < offsetof(fid_t, fid_data))
44 fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
46 if (zfsctl_is_node(ip))
47 rc = zfsctl_fid(ip, fid);
49 rc = zfs_fid(ip, fid);
51 len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
52 *max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);
54 return (rc == 0 ? FILEID_INO32_GEN : 255);
57 static struct dentry *
58 zpl_dentry_obtain_alias(struct inode *ip)
60 struct dentry *result;
62 #ifdef HAVE_D_OBTAIN_ALIAS
63 result = d_obtain_alias(ip);
65 result = d_alloc_anon(ip);
69 result = ERR_PTR(-ENOMEM);
71 #endif /* HAVE_D_OBTAIN_ALIAS */
76 static struct dentry *
77 zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
78 int fh_len, int fh_type)
80 fid_t *fid = (fid_t *)fh;
84 len_bytes = fh_len * sizeof (__u32);
86 if (fh_type != FILEID_INO32_GEN ||
87 len_bytes < offsetof(fid_t, fid_data) ||
88 len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
89 return ERR_PTR(-EINVAL);
91 rc = zfs_vget(sb, &ip, fid);
96 ASSERT((ip != NULL) && !IS_ERR(ip));
98 return zpl_dentry_obtain_alias(ip);
101 static struct dentry *
102 zpl_get_parent(struct dentry *child)
109 error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL);
111 ASSERT3S(error, <=, 0);
114 return ERR_PTR(error);
116 return zpl_dentry_obtain_alias(ip);
119 const struct export_operations zpl_export_operations = {
120 .encode_fh = zpl_encode_fh,
121 .fh_to_dentry = zpl_fh_to_dentry,
122 .get_parent = zpl_get_parent