Changes in 4.9.221 ext4: fix extent_status fragmentation for plain files net: ipv4: emulate READ_ONCE() on ->hdrincl bit-field in raw_sendmsg() net: ipv4: avoid unused variable warning for sysctl drm/msm: Use the correct dma_sync calls harder crypto: mxs-dcp - make symbols 'sha1_null_hash' and 'sha256_null_hash' static vti4: removed duplicate log message. watchdog: reset last_hw_keepalive time at start scsi: lpfc: Fix kasan slab-out-of-bounds error in lpfc_unreg_login ceph: return ceph_mdsc_do_request() errors from __get_parent() ceph: don't skip updating wanted caps when cap is stale pwm: rcar: Fix late Runtime PM enablement scsi: iscsi: Report unbind session event when the target has been removed ASoC: Intel: atom: Take the drv->lock mutex before calling sst_send_slot_map() kernel/gcov/fs.c: gcov_seq_next() should increase position index ipc/util.c: sysvipc_find_ipc() should increase position index s390/cio: avoid duplicated 'ADD' uevents pwm: renesas-tpu: Fix late Runtime PM enablement pwm: bcm2835: Dynamically allocate base PCI/ASPM: Allow re-enabling Clock PM ipv6: fix restrict IPV6_ADDRFORM operation macsec: avoid to set wrong mtu macvlan: fix null dereference in macvlan_device_event() net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node net/x25: Fix x25_neigh refcnt leak when receiving frame tcp: cache line align MAX_TCP_HEADER team: fix hang in team_mode_get() net: dsa: b53: Fix ARL register definitions xfrm: Always set XFRM_TRANSFORMED in xfrm{4,6}_output_finish ALSA: hda: Remove ASUS ROG Zenith from the blacklist iio: xilinx-xadc: Fix ADC-B powerdown iio: xilinx-xadc: Fix clearing interrupt when enabling trigger iio: xilinx-xadc: Fix sequencer configuration for aux channels in simultaneous mode fs/namespace.c: fix mountpoint reference counter race USB: sisusbvga: Change port variable from signed to unsigned USB: Add USB_QUIRK_DELAY_CTRL_MSG and USB_QUIRK_DELAY_INIT for Corsair K70 RGB RAPIDFIRE USB: core: Fix free-while-in-use bug in the USB S-Glibrary USB: hub: Fix handling of connect changes during sleep overflow.h: Add arithmetic shift helper vmalloc: fix remap_vmalloc_range() bounds checks ALSA: usx2y: Fix potential NULL dereference ALSA: usb-audio: Fix usb audio refcnt leak when getting spdif ALSA: usb-audio: Filter out unsupported sample rates on Focusrite devices tpm/tpm_tis: Free IRQ if probing fails KVM: Check validity of resolved slot when searching memslots KVM: VMX: Enable machine check support for 32bit targets tty: hvc: fix buffer overflow during hvc_alloc(). tty: rocket, avoid OOB access usb-storage: Add unusual_devs entry for JMicron JMS566 audit: check the length of userspace generated audit records ASoC: dapm: fixup dapm kcontrol widget ARM: imx: provide v7_cpu_resume() only on ARM_CPU_SUSPEND=y staging: comedi: dt2815: fix writing hi byte of analog output staging: comedi: Fix comedi_device refcnt leak in comedi_open staging: vt6656: Fix drivers TBTT timing counter. staging: vt6656: Power save stop wake_up_count wrap around. UAS: no use logging any details in case of ENODEV UAS: fix deadlock in error handling and PM flushing work usb: f_fs: Clear OS Extended descriptor counts to zero in ffs_data_reset() remoteproc: Fix wrong rvring index computation fuse: fix possibly missed wake-up after abort mtd: cfi: fix deadloop in cfi_cmdset_0002.c do_write_buffer usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete nfsd: memory corruption in nfsd4_lock() net/cxgb4: Check the return from t4_query_params properly perf/core: fix parent pid/tid in task exit events bpf, x86: Fix encoding for lower 8-bit registers in BPF_STX BPF_B xfs: fix partially uninitialized structure in xfs_reflink_remap_extent scsi: target: fix PR IN / READ FULL STATUS for FC objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings objtool: Support Clang non-section symbols in ORC dump xen/xenbus: ensure xenbus_map_ring_valloc() returns proper grant status ext4: convert BUG_ON's to WARN_ON's in mballoc.c hwmon: (jc42) Fix name to have no illegal characters ext4: avoid declaring fs inconsistent due to invalid file handles ext4: protect journal inode's blocks using block_validity ext4: don't perform block validity checks on the journal inode ext4: fix block validity checks for journal inodes using indirect blocks ext4: unsigned int compared against zero ext4: check for non-zero journal inum in ext4_calculate_overhead propagate_one(): mnt_set_mountpoint() needs mount_lock Linux 4.9.221 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ica420bdbb6c18fff9d0e6abffc180beefff0c5b9
265 lines
6.1 KiB
C
265 lines
6.1 KiB
C
#include <linux/ceph/ceph_debug.h>
|
|
|
|
#include <linux/exportfs.h>
|
|
#include <linux/slab.h>
|
|
#include <asm/unaligned.h>
|
|
|
|
#include "super.h"
|
|
#include "mds_client.h"
|
|
|
|
/*
|
|
* Basic fh
|
|
*/
|
|
struct ceph_nfs_fh {
|
|
u64 ino;
|
|
} __attribute__ ((packed));
|
|
|
|
/*
|
|
* Larger fh that includes parent ino.
|
|
*/
|
|
struct ceph_nfs_confh {
|
|
u64 ino, parent_ino;
|
|
} __attribute__ ((packed));
|
|
|
|
static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
|
|
struct inode *parent_inode)
|
|
{
|
|
int type;
|
|
struct ceph_nfs_fh *fh = (void *)rawfh;
|
|
struct ceph_nfs_confh *cfh = (void *)rawfh;
|
|
int connected_handle_length = sizeof(*cfh)/4;
|
|
int handle_length = sizeof(*fh)/4;
|
|
|
|
/* don't re-export snaps */
|
|
if (ceph_snap(inode) != CEPH_NOSNAP)
|
|
return -EINVAL;
|
|
|
|
if (parent_inode && (*max_len < connected_handle_length)) {
|
|
*max_len = connected_handle_length;
|
|
return FILEID_INVALID;
|
|
} else if (*max_len < handle_length) {
|
|
*max_len = handle_length;
|
|
return FILEID_INVALID;
|
|
}
|
|
|
|
if (parent_inode) {
|
|
dout("encode_fh %llx with parent %llx\n",
|
|
ceph_ino(inode), ceph_ino(parent_inode));
|
|
cfh->ino = ceph_ino(inode);
|
|
cfh->parent_ino = ceph_ino(parent_inode);
|
|
*max_len = connected_handle_length;
|
|
type = FILEID_INO32_GEN_PARENT;
|
|
} else {
|
|
dout("encode_fh %llx\n", ceph_ino(inode));
|
|
fh->ino = ceph_ino(inode);
|
|
*max_len = handle_length;
|
|
type = FILEID_INO32_GEN;
|
|
}
|
|
return type;
|
|
}
|
|
|
|
static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
|
|
{
|
|
struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
|
|
struct inode *inode;
|
|
struct dentry *dentry;
|
|
struct ceph_vino vino;
|
|
int err;
|
|
|
|
vino.ino = ino;
|
|
vino.snap = CEPH_NOSNAP;
|
|
inode = ceph_find_inode(sb, vino);
|
|
if (!inode) {
|
|
struct ceph_mds_request *req;
|
|
int mask;
|
|
|
|
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPINO,
|
|
USE_ANY_MDS);
|
|
if (IS_ERR(req))
|
|
return ERR_CAST(req);
|
|
|
|
mask = CEPH_STAT_CAP_INODE;
|
|
if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
|
|
mask |= CEPH_CAP_XATTR_SHARED;
|
|
req->r_args.getattr.mask = cpu_to_le32(mask);
|
|
|
|
req->r_ino1 = vino;
|
|
req->r_num_caps = 1;
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
|
inode = req->r_target_inode;
|
|
if (inode)
|
|
ihold(inode);
|
|
ceph_mdsc_put_request(req);
|
|
if (!inode)
|
|
return ERR_PTR(-ESTALE);
|
|
}
|
|
|
|
dentry = d_obtain_alias(inode);
|
|
if (IS_ERR(dentry))
|
|
return dentry;
|
|
err = ceph_init_dentry(dentry);
|
|
if (err < 0) {
|
|
dput(dentry);
|
|
return ERR_PTR(err);
|
|
}
|
|
dout("__fh_to_dentry %llx %p dentry %p\n", ino, inode, dentry);
|
|
return dentry;
|
|
}
|
|
|
|
/*
|
|
* convert regular fh to dentry
|
|
*/
|
|
static struct dentry *ceph_fh_to_dentry(struct super_block *sb,
|
|
struct fid *fid,
|
|
int fh_len, int fh_type)
|
|
{
|
|
struct ceph_nfs_fh *fh = (void *)fid->raw;
|
|
|
|
if (fh_type != FILEID_INO32_GEN &&
|
|
fh_type != FILEID_INO32_GEN_PARENT)
|
|
return NULL;
|
|
if (fh_len < sizeof(*fh) / 4)
|
|
return NULL;
|
|
|
|
dout("fh_to_dentry %llx\n", fh->ino);
|
|
return __fh_to_dentry(sb, fh->ino);
|
|
}
|
|
|
|
static struct dentry *__get_parent(struct super_block *sb,
|
|
struct dentry *child, u64 ino)
|
|
{
|
|
struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc;
|
|
struct ceph_mds_request *req;
|
|
struct inode *inode;
|
|
struct dentry *dentry;
|
|
int mask;
|
|
int err;
|
|
|
|
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPPARENT,
|
|
USE_ANY_MDS);
|
|
if (IS_ERR(req))
|
|
return ERR_CAST(req);
|
|
|
|
if (child) {
|
|
req->r_inode = d_inode(child);
|
|
ihold(d_inode(child));
|
|
} else {
|
|
req->r_ino1 = (struct ceph_vino) {
|
|
.ino = ino,
|
|
.snap = CEPH_NOSNAP,
|
|
};
|
|
}
|
|
|
|
mask = CEPH_STAT_CAP_INODE;
|
|
if (ceph_security_xattr_wanted(d_inode(sb->s_root)))
|
|
mask |= CEPH_CAP_XATTR_SHARED;
|
|
req->r_args.getattr.mask = cpu_to_le32(mask);
|
|
|
|
req->r_num_caps = 1;
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
|
if (err) {
|
|
ceph_mdsc_put_request(req);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
inode = req->r_target_inode;
|
|
if (inode)
|
|
ihold(inode);
|
|
ceph_mdsc_put_request(req);
|
|
if (!inode)
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
dentry = d_obtain_alias(inode);
|
|
if (IS_ERR(dentry))
|
|
return dentry;
|
|
err = ceph_init_dentry(dentry);
|
|
if (err < 0) {
|
|
dput(dentry);
|
|
return ERR_PTR(err);
|
|
}
|
|
dout("__get_parent ino %llx parent %p ino %llx.%llx\n",
|
|
child ? ceph_ino(d_inode(child)) : ino,
|
|
dentry, ceph_vinop(inode));
|
|
return dentry;
|
|
}
|
|
|
|
static struct dentry *ceph_get_parent(struct dentry *child)
|
|
{
|
|
/* don't re-export snaps */
|
|
if (ceph_snap(d_inode(child)) != CEPH_NOSNAP)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
dout("get_parent %p ino %llx.%llx\n",
|
|
child, ceph_vinop(d_inode(child)));
|
|
return __get_parent(child->d_sb, child, 0);
|
|
}
|
|
|
|
/*
|
|
* convert regular fh to parent
|
|
*/
|
|
static struct dentry *ceph_fh_to_parent(struct super_block *sb,
|
|
struct fid *fid,
|
|
int fh_len, int fh_type)
|
|
{
|
|
struct ceph_nfs_confh *cfh = (void *)fid->raw;
|
|
struct dentry *dentry;
|
|
|
|
if (fh_type != FILEID_INO32_GEN_PARENT)
|
|
return NULL;
|
|
if (fh_len < sizeof(*cfh) / 4)
|
|
return NULL;
|
|
|
|
dout("fh_to_parent %llx\n", cfh->parent_ino);
|
|
dentry = __get_parent(sb, NULL, cfh->ino);
|
|
if (unlikely(dentry == ERR_PTR(-ENOENT)))
|
|
dentry = __fh_to_dentry(sb, cfh->parent_ino);
|
|
return dentry;
|
|
}
|
|
|
|
static int ceph_get_name(struct dentry *parent, char *name,
|
|
struct dentry *child)
|
|
{
|
|
struct ceph_mds_client *mdsc;
|
|
struct ceph_mds_request *req;
|
|
int err;
|
|
|
|
mdsc = ceph_inode_to_client(d_inode(child))->mdsc;
|
|
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME,
|
|
USE_ANY_MDS);
|
|
if (IS_ERR(req))
|
|
return PTR_ERR(req);
|
|
|
|
inode_lock(d_inode(parent));
|
|
|
|
req->r_inode = d_inode(child);
|
|
ihold(d_inode(child));
|
|
req->r_ino2 = ceph_vino(d_inode(parent));
|
|
req->r_locked_dir = d_inode(parent);
|
|
req->r_num_caps = 2;
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
|
|
|
inode_unlock(d_inode(parent));
|
|
|
|
if (!err) {
|
|
struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
|
|
memcpy(name, rinfo->dname, rinfo->dname_len);
|
|
name[rinfo->dname_len] = 0;
|
|
dout("get_name %p ino %llx.%llx name %s\n",
|
|
child, ceph_vinop(d_inode(child)), name);
|
|
} else {
|
|
dout("get_name %p ino %llx.%llx err %d\n",
|
|
child, ceph_vinop(d_inode(child)), err);
|
|
}
|
|
|
|
ceph_mdsc_put_request(req);
|
|
return err;
|
|
}
|
|
|
|
const struct export_operations ceph_export_ops = {
|
|
.encode_fh = ceph_encode_fh,
|
|
.fh_to_dentry = ceph_fh_to_dentry,
|
|
.fh_to_parent = ceph_fh_to_parent,
|
|
.get_parent = ceph_get_parent,
|
|
.get_name = ceph_get_name,
|
|
};
|