2011-04-28 20:35:50 +04:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Gunnar Beutner
|
2012-09-16 10:03:04 +04:00
|
|
|
* Copyright (c) 2012 Cyril Plisko. All rights reserved.
|
2011-04-28 20:35:50 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/zfs_vnops.h>
|
|
|
|
#include <sys/zfs_znode.h>
|
2011-11-11 11:15:53 +04:00
|
|
|
#include <sys/zfs_ctldir.h>
|
2011-04-28 20:35:50 +04:00
|
|
|
#include <sys/zpl.h>
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2012-07-23 21:55:48 +04:00
|
|
|
#ifdef HAVE_ENCODE_FH_WITH_INODE
|
|
|
|
zpl_encode_fh(struct inode *ip, __u32 *fh, int *max_len, struct inode *parent)
|
|
|
|
{
|
|
|
|
#else
|
2011-04-28 20:35:50 +04:00
|
|
|
zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
|
|
|
|
{
|
2016-12-12 21:46:26 +03:00
|
|
|
/* CSTYLED */
|
2011-04-28 20:35:50 +04:00
|
|
|
struct inode *ip = dentry->d_inode;
|
2012-07-23 21:55:48 +04:00
|
|
|
#endif /* HAVE_ENCODE_FH_WITH_INODE */
|
2015-04-14 20:25:50 +03:00
|
|
|
fstrans_cookie_t cookie;
|
2012-07-23 21:55:48 +04:00
|
|
|
fid_t *fid = (fid_t *)fh;
|
2011-04-28 20:35:50 +04:00
|
|
|
int len_bytes, rc;
|
|
|
|
|
|
|
|
len_bytes = *max_len * sizeof (__u32);
|
|
|
|
|
|
|
|
if (len_bytes < offsetof(fid_t, fid_data))
|
2013-11-01 23:26:11 +04:00
|
|
|
return (255);
|
2011-04-28 20:35:50 +04:00
|
|
|
|
|
|
|
fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
|
2015-04-14 20:25:50 +03:00
|
|
|
cookie = spl_fstrans_mark();
|
2011-04-28 20:35:50 +04:00
|
|
|
|
2011-11-11 11:15:53 +04:00
|
|
|
if (zfsctl_is_node(ip))
|
|
|
|
rc = zfsctl_fid(ip, fid);
|
|
|
|
else
|
|
|
|
rc = zfs_fid(ip, fid);
|
2011-04-28 20:35:50 +04:00
|
|
|
|
2015-04-14 20:25:50 +03:00
|
|
|
spl_fstrans_unmark(cookie);
|
2011-04-28 20:35:50 +04:00
|
|
|
len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
|
|
|
|
*max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);
|
|
|
|
|
|
|
|
return (rc == 0 ? FILEID_INO32_GEN : 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *
|
|
|
|
zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
|
|
|
|
int fh_len, int fh_type)
|
|
|
|
{
|
|
|
|
fid_t *fid = (fid_t *)fh;
|
2015-04-14 20:25:50 +03:00
|
|
|
fstrans_cookie_t cookie;
|
2011-04-28 20:35:50 +04:00
|
|
|
struct inode *ip;
|
|
|
|
int len_bytes, rc;
|
|
|
|
|
|
|
|
len_bytes = fh_len * sizeof (__u32);
|
|
|
|
|
|
|
|
if (fh_type != FILEID_INO32_GEN ||
|
|
|
|
len_bytes < offsetof(fid_t, fid_data) ||
|
|
|
|
len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
|
2013-11-01 23:26:11 +04:00
|
|
|
return (ERR_PTR(-EINVAL));
|
2011-04-28 20:35:50 +04:00
|
|
|
|
2015-04-14 20:25:50 +03:00
|
|
|
cookie = spl_fstrans_mark();
|
2011-05-19 22:44:07 +04:00
|
|
|
rc = zfs_vget(sb, &ip, fid);
|
2015-04-14 20:25:50 +03:00
|
|
|
spl_fstrans_unmark(cookie);
|
2011-04-28 20:35:50 +04:00
|
|
|
|
2015-05-12 23:30:19 +03:00
|
|
|
if (rc) {
|
|
|
|
/*
|
|
|
|
* If we see ENOENT it might mean that an NFSv4 * client
|
|
|
|
* is using a cached inode value in a file handle and
|
|
|
|
* that the sought after file has had its inode changed
|
|
|
|
* by a third party. So change the error to ESTALE
|
|
|
|
* which will trigger a full lookup by the client and
|
|
|
|
* will find the new filename/inode pair if it still
|
|
|
|
* exists.
|
|
|
|
*/
|
|
|
|
if (rc == ENOENT)
|
|
|
|
rc = ESTALE;
|
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
return (ERR_PTR(-rc));
|
2015-05-12 23:30:19 +03:00
|
|
|
}
|
2011-04-28 20:35:50 +04:00
|
|
|
|
|
|
|
ASSERT((ip != NULL) && !IS_ERR(ip));
|
|
|
|
|
2019-11-12 19:59:06 +03:00
|
|
|
return (d_obtain_alias(ip));
|
2011-04-28 20:35:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *
|
|
|
|
zpl_get_parent(struct dentry *child)
|
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
2015-04-14 20:25:50 +03:00
|
|
|
fstrans_cookie_t cookie;
|
2011-04-28 20:35:50 +04:00
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
2015-04-14 20:25:50 +03:00
|
|
|
cookie = spl_fstrans_mark();
|
2011-04-28 20:35:50 +04:00
|
|
|
error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL);
|
2015-04-14 20:25:50 +03:00
|
|
|
spl_fstrans_unmark(cookie);
|
2011-04-28 20:35:50 +04:00
|
|
|
crfree(cr);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
|
|
|
|
if (error)
|
2013-11-01 23:26:11 +04:00
|
|
|
return (ERR_PTR(error));
|
2011-04-28 20:35:50 +04:00
|
|
|
|
2019-11-12 19:59:06 +03:00
|
|
|
return (d_obtain_alias(ip));
|
2011-04-28 20:35:50 +04:00
|
|
|
}
|
|
|
|
|
2012-09-16 10:03:04 +04:00
|
|
|
static int
|
|
|
|
zpl_commit_metadata(struct inode *inode)
|
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
2015-04-14 20:25:50 +03:00
|
|
|
fstrans_cookie_t cookie;
|
2012-09-16 10:03:04 +04:00
|
|
|
int error;
|
|
|
|
|
2013-08-12 22:47:04 +04:00
|
|
|
if (zfsctl_is_node(inode))
|
|
|
|
return (0);
|
|
|
|
|
2012-09-16 10:03:04 +04:00
|
|
|
crhold(cr);
|
2015-04-14 20:25:50 +03:00
|
|
|
cookie = spl_fstrans_mark();
|
2012-09-16 10:03:04 +04:00
|
|
|
error = -zfs_fsync(inode, 0, cr);
|
2015-04-14 20:25:50 +03:00
|
|
|
spl_fstrans_unmark(cookie);
|
2012-09-16 10:03:04 +04:00
|
|
|
crfree(cr);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
return (error);
|
2012-09-16 10:03:04 +04:00
|
|
|
}
|
|
|
|
|
2011-04-28 20:35:50 +04:00
|
|
|
const struct export_operations zpl_export_operations = {
|
2013-11-01 23:26:11 +04:00
|
|
|
.encode_fh = zpl_encode_fh,
|
|
|
|
.fh_to_dentry = zpl_fh_to_dentry,
|
|
|
|
.get_parent = zpl_get_parent,
|
|
|
|
.commit_metadata = zpl_commit_metadata,
|
2011-04-28 20:35:50 +04:00
|
|
|
};
|