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
23 * Copyright (c) 2012 Cyril Plisko. All rights reserved.
27 #include <sys/zfs_vnops.h>
28 #include <sys/zfs_znode.h>
29 #include <sys/zfs_ctldir.h>
34 #ifdef HAVE_ENCODE_FH_WITH_INODE
35 zpl_encode_fh(struct inode *ip, __u32 *fh, int *max_len, struct inode *parent)
38 zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
40 struct inode *ip = dentry->d_inode;
41 #endif /* HAVE_ENCODE_FH_WITH_INODE */
42 fid_t *fid = (fid_t *)fh;
45 len_bytes = *max_len * sizeof (__u32);
47 if (len_bytes < offsetof(fid_t, fid_data))
50 fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
52 if (zfsctl_is_node(ip))
53 rc = zfsctl_fid(ip, fid);
55 rc = zfs_fid(ip, fid);
57 len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
58 *max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);
60 return (rc == 0 ? FILEID_INO32_GEN : 255);
63 static struct dentry *
64 zpl_dentry_obtain_alias(struct inode *ip)
66 struct dentry *result;
68 #ifdef HAVE_D_OBTAIN_ALIAS
69 result = d_obtain_alias(ip);
71 result = d_alloc_anon(ip);
75 result = ERR_PTR(-ENOMEM);
77 #endif /* HAVE_D_OBTAIN_ALIAS */
82 static struct dentry *
83 zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
84 int fh_len, int fh_type)
86 fid_t *fid = (fid_t *)fh;
90 len_bytes = fh_len * sizeof (__u32);
92 if (fh_type != FILEID_INO32_GEN ||
93 len_bytes < offsetof(fid_t, fid_data) ||
94 len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
95 return ERR_PTR(-EINVAL);
97 rc = zfs_vget(sb, &ip, fid);
102 ASSERT((ip != NULL) && !IS_ERR(ip));
104 return zpl_dentry_obtain_alias(ip);
107 static struct dentry *
108 zpl_get_parent(struct dentry *child)
115 error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL);
117 ASSERT3S(error, <=, 0);
120 return ERR_PTR(error);
122 return zpl_dentry_obtain_alias(ip);
125 #ifdef HAVE_COMMIT_METADATA
127 zpl_commit_metadata(struct inode *inode)
133 error = -zfs_fsync(inode, 0, cr);
135 ASSERT3S(error, <=, 0);
139 #endif /* HAVE_COMMIT_METADATA */
141 const struct export_operations zpl_export_operations = {
142 .encode_fh = zpl_encode_fh,
143 .fh_to_dentry = zpl_fh_to_dentry,
144 .get_parent = zpl_get_parent,
145 #ifdef HAVE_COMMIT_METADATA
146 .commit_metadata= zpl_commit_metadata,
147 #endif /* HAVE_COMMIT_METADATA */