Also revert commit b91d532928df ("ipv6: set rt6i_protocol properly in the route when it is installed") as it breaks the test systems. Changes in 4.9.136 xfrm: Validate address prefix lengths in the xfrm selector. xfrm6: call kfree_skb when skb is toobig mac80211: Always report TX status cfg80211: reg: Init wiphy_idx in regulatory_hint_core() mac80211: fix pending queue hang due to TX_DROP cfg80211: Address some corner cases in scan result channel updating mac80211: TDLS: fix skb queue/priority assignment ARM: 8799/1: mm: fix pci_ioremap_io() offset check xfrm: validate template mode ARM: dts: BCM63xx: Fix incorrect interrupt specifiers net: macb: Clean 64b dma addresses if they are not detected soc: fsl: qbman: qman: avoid allocating from non existing gen_pool soc: fsl: qe: Fix copy/paste bug in ucc_get_tdm_sync_shift() nl80211: Fix possible Spectre-v1 for NL80211_TXRATE_HT mac80211_hwsim: do not omit multicast announce of first added radio Bluetooth: SMP: fix crash in unpairing pxa168fb: prepare the clock qed: Avoid implicit enum conversion in qed_roce_mode_to_flavor qed: Avoid constant logical operation warning in qed_vf_pf_acquire asix: Check for supported Wake-on-LAN modes ax88179_178a: Check for supported Wake-on-LAN modes lan78xx: Check for supported Wake-on-LAN modes sr9800: Check for supported Wake-on-LAN modes r8152: Check for supported Wake-on-LAN Modes smsc75xx: Check for Wake-on-LAN modes smsc95xx: Check for Wake-on-LAN modes perf/ring_buffer: Prevent concurent ring buffer access perf/x86/intel/uncore: Fix PCI BDF address of M3UPI on SKX net: fec: fix rare tx timeout declance: Fix continuation with the adapter identification message net: cxgb3_main: fix a missing-check bug perf symbols: Fix memory corruption because of zero length symbols mm/memory_hotplug.c: fix overflow in test_pages_in_a_zone() MIPS: microMIPS: Fix decoding of swsp16 instruction MIPS: Handle non word sized instructions when examining frame scsi: aacraid: Fix typo in blink status f2fs: fix multiple f2fs_add_link() having same name for inline dentry igb: Remove superfluous reset to PHY and page 0 selection ACPI: sysfs: Make ACPI GPE mask kernel parameter cover all GPEs PCI: Disable MSI for HiSilicon Hip06/Hip07 only in Root Port mode i2c: bcm2835: Avoid possible NULL ptr dereference efi/fb: Correct PCI_STD_RESOURCE_END usage ipv6: set rt6i_protocol properly in the route when it is installed platform/x86: acer-wmi: setup accelerometer when ACPI device was found IB/ipoib: Do not warn if IPoIB debugfs doesn't exist IB/core: Fix the validations of a multicast LID in attach or detach operations orangefs: off by ones in xattr size checks rxe: Fix a sleep-in-atomic bug in post_one_send nvme-pci: fix CMB sysfs file removal in reset path net: phy: marvell: Limit 88m1101 autoneg errata to 88E1145 as well. net/mlx5: Fix command completion after timeout access invalid structure tipc: Fix tipc_sk_reinit handling of -EAGAIN tipc: fix a race condition of releasing subscriber object bnxt_en: Don't use rtnl lock to protect link change logic in workqueue. ath10k: fix NAPI enable/disable symmetry for AHB interface ARM: dts: bcm283x: Reserve first page for firmware btrfs: fiemap: Cache and merge fiemap extent before submit it to user ata: sata_rcar: Handle return value of clk_prepare_enable reset: hi6220: Set module license so that it can be loaded ASoC: Intel: Skylake: Fix to parse consecutive string tkns in manifest arch/sparc: increase CONFIG_NODES_SHIFT on SPARC64 to 5 mac80211: fix TX aggregation start/stop callback race libata: fix error checking in in ata_parse_force_one() net: ethernet: stmmac: Fix altr_tse_pcs SGMII Initialization qlcnic: Fix tunnel offload for 82xx adapters x86/cpu/cyrix: Add alternative Device ID of Geode GX1 SoC ARM: 8677/1: boot/compressed: fix decompressor header layout for v7-M gpu: ipu-v3: Fix CSI selection for VDIC elevator: fix truncation of icq_cache_name net: stmmac: ensure jumbo_frm error return is correctly checked for -ve value Btrfs: clear EXTENT_DEFRAG bits in finish_ordered_io ufs: we need to sync inode before freeing it net/mlx5e: Fix fixpoint divide exception in mlx5e_am_stats_compare ip6_tunnel: Correct tos value in collect_md mode net/mlx5: Fix driver load error flow when firmware is stuck perf evsel: Fix probing of precise_ip level for default cycles event perf probe: Fix probe definition for inlined functions net/mlx5: Fix health work queue spin lock to IRQ safe usb: renesas_usbhs: gadget: fix spin_lock_init() for &uep->lock usb: renesas_usbhs: gadget: fix unused-but-set-variable warning usb: dwc3: omap: remove IRQ_NOAUTOEN used with shared irq clk: samsung: Fix m2m scaler clock on Exynos542x ptr_ring: fix up after recent ptr_ring changes staging: wilc1000: Fix problem with wrong vif index rds: ib: Fix missing call to rds_ib_dev_put in rds_ib_setup_qp iio: adc: Revert "axp288: Drop bogus AXP288_ADC_TS_PIN_CTRL register modifications" qed: Warn PTT usage by wrong hw-function ocfs2: fix deadlock caused by recursive locking in xattr net: cdc_ncm: GetNtbFormat endian fix sctp: use right member as the param of list_for_each_entry ALSA: hda - No loopback on ALC299 codec ath10k: convert warning about non-existent OTP board id to debug message ipv6: fix cleanup ordering for ip6_mr failure IB/ipoib: Fix lockdep issue found on ipoib_ib_dev_heavy_flush IB/rxe: put the pool on allocation failure nbd: only set MSG_MORE when we have more to send mm/frame_vector.c: release a semaphore in 'get_vaddr_frames()' IB/mlx5: Avoid passing an invalid QP type to firmware scsi: qla2xxx: Avoid double completion of abort command drm: bochs: Don't remove uninitialized fbdev framebuffer i40e: avoid NVM acquire deadlock during NVM update Revert "IB/ipoib: Update broadcast object if PKey value was changed in index 0" Btrfs: incremental send, fix invalid memory access drm/msm: Fix possible null dereference on failure of get_pages() module: fix DEBUG_SET_MODULE_RONX typo iio: pressure: zpa2326: Remove always-true check which confuses gcc l2tp: remove configurable payload offset macsec: fix memory leaks when skb_to_sgvec fails perf/core: Fix locking for children siblings group read cifs: Use ULL suffix for 64-bit constant futex: futex_wake_op, do not fail on invalid op ALSA: hda - Fix incorrect usage of IS_REACHABLE() test_bpf: Fix testing with CONFIG_BPF_JIT_ALWAYS_ON=y on other arches xen-netfront: Update features after registering netdev sparc64: Fix regression in pmdp_invalidate(). xen-netfront: Fix mismatched rtnl_unlock enic: do not overwrite error code bonding: ratelimit failed speed/duplex update warning nvmet: fix space padding in serial number iio: buffer: fix the function signature to match implementation x86/paravirt: Fix some warning messages IB/mlx4: Fix an error handling path in 'mlx4_ib_rereg_user_mr()' libertas: call into generic suspend code before turning off power xhci: Fix USB3 NULL pointer dereference at logical disconnect. perf tests: Fix indexing when invoking subtests ARM: dts: imx53-qsb: disable 1.2GHz OPP rxrpc: Don't check RXRPC_CALL_TX_LAST after calling rxrpc_rotate_tx_window() rxrpc: Only take the rwind and mtu values from latest ACK net: ena: fix NULL dereference due to untimely napi initialization fs/fat/fatent.c: add cond_resched() to fat_count_free_clusters() mtd: spi-nor: Add support for is25wp series chips Revert "netfilter: ipv6: nf_defrag: drop skb dst before queueing" perf tools: Disable parallelism for 'make clean' bridge: do not add port to router list when receives query with source 0.0.0.0 net: bridge: remove ipv6 zero address check in mcast queries ipv6: mcast: fix a use-after-free in inet6_mc_check ipv6/ndisc: Preserve IPv6 control buffer if protocol error handlers are called llc: set SOCK_RCU_FREE in llc_sap_add_socket() net/ipv6: Fix index counter for unicast addresses in in6_dump_addrs net: sched: gred: pass the right attribute to gred_change_table_def() net: socket: fix a missing-check bug net: stmmac: Fix stmmac_mdio_reset() when building stmmac as modules net: udp: fix handling of CHECKSUM_COMPLETE packets r8169: fix NAPI handling under high load sctp: fix race on sctp_id2asoc vhost: Fix Spectre V1 vulnerability ethtool: fix a privilege escalation bug bonding: fix length of actor system net: drop skb on failure in ip_check_defrag() net: fix pskb_trim_rcsum_slow() with odd trim offset rtnetlink: Disallow FDB configuration for non-Ethernet device ip6_tunnel: Fix encapsulation layout Revert "x86/mm: Expand static page table for fixmap space" crypto: shash - Fix a sleep-in-atomic bug in shash_setkey_unaligned ahci: don't ignore result code of ahci_reset_controller() gpio: mxs: Get rid of external API call xfs: truncate transaction does not modify the inobt cachefiles: fix the race between cachefiles_bury_object() and rmdir(2) ptp: fix Spectre v1 vulnerability drm/edid: Add 6 bpc quirk for BOE panel in HP Pavilion 15-n233sl RDMA/ucma: Fix Spectre v1 vulnerability IB/ucm: Fix Spectre v1 vulnerability cdc-acm: correct counting of UART states in serial state notification usb: gadget: storage: Fix Spectre v1 vulnerability USB: fix the usbfs flag sanitization for control transfers Input: elan_i2c - add ACPI ID for Lenovo IdeaPad 330-15IGM sched/fair: Fix throttle_list starvation with low CFS quota x86/percpu: Fix this_cpu_read() x86/time: Correct the attribute on jiffies' definition net: fs_enet: do not call phy_stop() in interrupts posix-timers: Sanitize overrun handling Linux 4.9.136 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
457 lines
12 KiB
C
457 lines
12 KiB
C
/*
|
|
* (C) 2001 Clemson University and The University of Chicago
|
|
*
|
|
* See COPYING in top-level directory.
|
|
*/
|
|
|
|
/*
|
|
* Linux VFS extended attribute operations.
|
|
*/
|
|
|
|
#include "protocol.h"
|
|
#include "orangefs-kernel.h"
|
|
#include "orangefs-bufmap.h"
|
|
#include <linux/posix_acl_xattr.h>
|
|
#include <linux/xattr.h>
|
|
|
|
|
|
#define SYSTEM_ORANGEFS_KEY "system.pvfs2."
|
|
#define SYSTEM_ORANGEFS_KEY_LEN 13
|
|
|
|
/*
|
|
* this function returns
|
|
* 0 if the key corresponding to name is not meant to be printed as part
|
|
* of a listxattr.
|
|
* 1 if the key corresponding to name is meant to be returned as part of
|
|
* a listxattr.
|
|
* The ones that start SYSTEM_ORANGEFS_KEY are the ones to avoid printing.
|
|
*/
|
|
static int is_reserved_key(const char *key, size_t size)
|
|
{
|
|
|
|
if (size < SYSTEM_ORANGEFS_KEY_LEN)
|
|
return 1;
|
|
|
|
return strncmp(key, SYSTEM_ORANGEFS_KEY, SYSTEM_ORANGEFS_KEY_LEN) ? 1 : 0;
|
|
}
|
|
|
|
static inline int convert_to_internal_xattr_flags(int setxattr_flags)
|
|
{
|
|
int internal_flag = 0;
|
|
|
|
if (setxattr_flags & XATTR_REPLACE) {
|
|
/* Attribute must exist! */
|
|
internal_flag = ORANGEFS_XATTR_REPLACE;
|
|
} else if (setxattr_flags & XATTR_CREATE) {
|
|
/* Attribute must not exist */
|
|
internal_flag = ORANGEFS_XATTR_CREATE;
|
|
}
|
|
return internal_flag;
|
|
}
|
|
|
|
|
|
/*
|
|
* Tries to get a specified key's attributes of a given
|
|
* file into a user-specified buffer. Note that the getxattr
|
|
* interface allows for the users to probe the size of an
|
|
* extended attribute by passing in a value of 0 to size.
|
|
* Thus our return value is always the size of the attribute
|
|
* unless the key does not exist for the file and/or if
|
|
* there were errors in fetching the attribute value.
|
|
*/
|
|
ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
|
|
void *buffer, size_t size)
|
|
{
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
struct orangefs_kernel_op_s *new_op = NULL;
|
|
ssize_t ret = -ENOMEM;
|
|
ssize_t length = 0;
|
|
int fsuid;
|
|
int fsgid;
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"%s: name %s, buffer_size %zd\n",
|
|
__func__, name, size);
|
|
|
|
if (S_ISLNK(inode->i_mode))
|
|
return -EOPNOTSUPP;
|
|
|
|
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
|
|
return -EINVAL;
|
|
|
|
fsuid = from_kuid(&init_user_ns, current_fsuid());
|
|
fsgid = from_kgid(&init_user_ns, current_fsgid());
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"getxattr on inode %pU, name %s "
|
|
"(uid %o, gid %o)\n",
|
|
get_khandle_from_ino(inode),
|
|
name,
|
|
fsuid,
|
|
fsgid);
|
|
|
|
down_read(&orangefs_inode->xattr_sem);
|
|
|
|
new_op = op_alloc(ORANGEFS_VFS_OP_GETXATTR);
|
|
if (!new_op)
|
|
goto out_unlock;
|
|
|
|
new_op->upcall.req.getxattr.refn = orangefs_inode->refn;
|
|
strcpy(new_op->upcall.req.getxattr.key, name);
|
|
|
|
/*
|
|
* NOTE: Although keys are meant to be NULL terminated textual
|
|
* strings, I am going to explicitly pass the length just in case
|
|
* we change this later on...
|
|
*/
|
|
new_op->upcall.req.getxattr.key_sz = strlen(name) + 1;
|
|
|
|
ret = service_operation(new_op, "orangefs_inode_getxattr",
|
|
get_interruptible_flag(inode));
|
|
if (ret != 0) {
|
|
if (ret == -ENOENT) {
|
|
ret = -ENODATA;
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_getxattr: inode %pU key %s"
|
|
" does not exist!\n",
|
|
get_khandle_from_ino(inode),
|
|
(char *)new_op->upcall.req.getxattr.key);
|
|
}
|
|
goto out_release_op;
|
|
}
|
|
|
|
/*
|
|
* Length returned includes null terminator.
|
|
*/
|
|
length = new_op->downcall.resp.getxattr.val_sz;
|
|
|
|
/*
|
|
* Just return the length of the queried attribute.
|
|
*/
|
|
if (size == 0) {
|
|
ret = length;
|
|
goto out_release_op;
|
|
}
|
|
|
|
/*
|
|
* Check to see if key length is > provided buffer size.
|
|
*/
|
|
if (length > size) {
|
|
ret = -ERANGE;
|
|
goto out_release_op;
|
|
}
|
|
|
|
memcpy(buffer, new_op->downcall.resp.getxattr.val, length);
|
|
memset(buffer + length, 0, size - length);
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_getxattr: inode %pU "
|
|
"key %s key_sz %d, val_len %d\n",
|
|
get_khandle_from_ino(inode),
|
|
(char *)new_op->
|
|
upcall.req.getxattr.key,
|
|
(int)new_op->
|
|
upcall.req.getxattr.key_sz,
|
|
(int)ret);
|
|
|
|
ret = length;
|
|
|
|
out_release_op:
|
|
op_release(new_op);
|
|
out_unlock:
|
|
up_read(&orangefs_inode->xattr_sem);
|
|
return ret;
|
|
}
|
|
|
|
static int orangefs_inode_removexattr(struct inode *inode, const char *name,
|
|
int flags)
|
|
{
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
struct orangefs_kernel_op_s *new_op = NULL;
|
|
int ret = -ENOMEM;
|
|
|
|
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
|
|
return -EINVAL;
|
|
|
|
down_write(&orangefs_inode->xattr_sem);
|
|
new_op = op_alloc(ORANGEFS_VFS_OP_REMOVEXATTR);
|
|
if (!new_op)
|
|
goto out_unlock;
|
|
|
|
new_op->upcall.req.removexattr.refn = orangefs_inode->refn;
|
|
/*
|
|
* NOTE: Although keys are meant to be NULL terminated
|
|
* textual strings, I am going to explicitly pass the
|
|
* length just in case we change this later on...
|
|
*/
|
|
strcpy(new_op->upcall.req.removexattr.key, name);
|
|
new_op->upcall.req.removexattr.key_sz = strlen(name) + 1;
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_removexattr: key %s, key_sz %d\n",
|
|
(char *)new_op->upcall.req.removexattr.key,
|
|
(int)new_op->upcall.req.removexattr.key_sz);
|
|
|
|
ret = service_operation(new_op,
|
|
"orangefs_inode_removexattr",
|
|
get_interruptible_flag(inode));
|
|
if (ret == -ENOENT) {
|
|
/*
|
|
* Request to replace a non-existent attribute is an error.
|
|
*/
|
|
if (flags & XATTR_REPLACE)
|
|
ret = -ENODATA;
|
|
else
|
|
ret = 0;
|
|
}
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_removexattr: returning %d\n", ret);
|
|
|
|
op_release(new_op);
|
|
out_unlock:
|
|
up_write(&orangefs_inode->xattr_sem);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Tries to set an attribute for a given key on a file.
|
|
*
|
|
* Returns a -ve number on error and 0 on success. Key is text, but value
|
|
* can be binary!
|
|
*/
|
|
int orangefs_inode_setxattr(struct inode *inode, const char *name,
|
|
const void *value, size_t size, int flags)
|
|
{
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
struct orangefs_kernel_op_s *new_op;
|
|
int internal_flag = 0;
|
|
int ret = -ENOMEM;
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"%s: name %s, buffer_size %zd\n",
|
|
__func__, name, size);
|
|
|
|
if (size > ORANGEFS_MAX_XATTR_VALUELEN)
|
|
return -EINVAL;
|
|
if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN)
|
|
return -EINVAL;
|
|
|
|
internal_flag = convert_to_internal_xattr_flags(flags);
|
|
|
|
/* This is equivalent to a removexattr */
|
|
if (size == 0 && value == NULL) {
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"removing xattr (%s)\n",
|
|
name);
|
|
return orangefs_inode_removexattr(inode, name, flags);
|
|
}
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"setxattr on inode %pU, name %s\n",
|
|
get_khandle_from_ino(inode),
|
|
name);
|
|
|
|
down_write(&orangefs_inode->xattr_sem);
|
|
new_op = op_alloc(ORANGEFS_VFS_OP_SETXATTR);
|
|
if (!new_op)
|
|
goto out_unlock;
|
|
|
|
|
|
new_op->upcall.req.setxattr.refn = orangefs_inode->refn;
|
|
new_op->upcall.req.setxattr.flags = internal_flag;
|
|
/*
|
|
* NOTE: Although keys are meant to be NULL terminated textual
|
|
* strings, I am going to explicitly pass the length just in
|
|
* case we change this later on...
|
|
*/
|
|
strcpy(new_op->upcall.req.setxattr.keyval.key, name);
|
|
new_op->upcall.req.setxattr.keyval.key_sz = strlen(name) + 1;
|
|
memcpy(new_op->upcall.req.setxattr.keyval.val, value, size);
|
|
new_op->upcall.req.setxattr.keyval.val_sz = size;
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_setxattr: key %s, key_sz %d "
|
|
" value size %zd\n",
|
|
(char *)new_op->upcall.req.setxattr.keyval.key,
|
|
(int)new_op->upcall.req.setxattr.keyval.key_sz,
|
|
size);
|
|
|
|
ret = service_operation(new_op,
|
|
"orangefs_inode_setxattr",
|
|
get_interruptible_flag(inode));
|
|
|
|
gossip_debug(GOSSIP_XATTR_DEBUG,
|
|
"orangefs_inode_setxattr: returning %d\n",
|
|
ret);
|
|
|
|
/* when request is serviced properly, free req op struct */
|
|
op_release(new_op);
|
|
out_unlock:
|
|
up_write(&orangefs_inode->xattr_sem);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Tries to get a specified object's keys into a user-specified buffer of a
|
|
* given size. Note that like the previous instances of xattr routines, this
|
|
* also allows you to pass in a NULL pointer and 0 size to probe the size for
|
|
* subsequent memory allocations. Thus our return value is always the size of
|
|
* all the keys unless there were errors in fetching the keys!
|
|
*/
|
|
ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
|
{
|
|
struct inode *inode = dentry->d_inode;
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
struct orangefs_kernel_op_s *new_op;
|
|
__u64 token = ORANGEFS_ITERATE_START;
|
|
ssize_t ret = -ENOMEM;
|
|
ssize_t total = 0;
|
|
int count_keys = 0;
|
|
int key_size;
|
|
int i = 0;
|
|
int returned_count = 0;
|
|
|
|
if (size > 0 && buffer == NULL) {
|
|
gossip_err("%s: bogus NULL pointers\n", __func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
down_read(&orangefs_inode->xattr_sem);
|
|
new_op = op_alloc(ORANGEFS_VFS_OP_LISTXATTR);
|
|
if (!new_op)
|
|
goto out_unlock;
|
|
|
|
if (buffer && size > 0)
|
|
memset(buffer, 0, size);
|
|
|
|
try_again:
|
|
key_size = 0;
|
|
new_op->upcall.req.listxattr.refn = orangefs_inode->refn;
|
|
new_op->upcall.req.listxattr.token = token;
|
|
new_op->upcall.req.listxattr.requested_count =
|
|
(size == 0) ? 0 : ORANGEFS_MAX_XATTR_LISTLEN;
|
|
ret = service_operation(new_op, __func__,
|
|
get_interruptible_flag(inode));
|
|
if (ret != 0)
|
|
goto done;
|
|
|
|
if (size == 0) {
|
|
/*
|
|
* This is a bit of a big upper limit, but I did not want to
|
|
* spend too much time getting this correct, since users end
|
|
* up allocating memory rather than us...
|
|
*/
|
|
total = new_op->downcall.resp.listxattr.returned_count *
|
|
ORANGEFS_MAX_XATTR_NAMELEN;
|
|
goto done;
|
|
}
|
|
|
|
returned_count = new_op->downcall.resp.listxattr.returned_count;
|
|
if (returned_count < 0 ||
|
|
returned_count > ORANGEFS_MAX_XATTR_LISTLEN) {
|
|
gossip_err("%s: impossible value for returned_count:%d:\n",
|
|
__func__,
|
|
returned_count);
|
|
ret = -EIO;
|
|
goto done;
|
|
}
|
|
|
|
/*
|
|
* Check to see how much can be fit in the buffer. Fit only whole keys.
|
|
*/
|
|
for (i = 0; i < returned_count; i++) {
|
|
if (new_op->downcall.resp.listxattr.lengths[i] < 0 ||
|
|
new_op->downcall.resp.listxattr.lengths[i] >
|
|
ORANGEFS_MAX_XATTR_NAMELEN) {
|
|
gossip_err("%s: impossible value for lengths[%d]\n",
|
|
__func__,
|
|
new_op->downcall.resp.listxattr.lengths[i]);
|
|
ret = -EIO;
|
|
goto done;
|
|
}
|
|
if (total + new_op->downcall.resp.listxattr.lengths[i] > size)
|
|
goto done;
|
|
|
|
/*
|
|
* Since many dumb programs try to setxattr() on our reserved
|
|
* xattrs this is a feeble attempt at defeating those by not
|
|
* listing them in the output of listxattr.. sigh
|
|
*/
|
|
if (is_reserved_key(new_op->downcall.resp.listxattr.key +
|
|
key_size,
|
|
new_op->downcall.resp.
|
|
listxattr.lengths[i])) {
|
|
gossip_debug(GOSSIP_XATTR_DEBUG, "Copying key %d -> %s\n",
|
|
i, new_op->downcall.resp.listxattr.key +
|
|
key_size);
|
|
memcpy(buffer + total,
|
|
new_op->downcall.resp.listxattr.key + key_size,
|
|
new_op->downcall.resp.listxattr.lengths[i]);
|
|
total += new_op->downcall.resp.listxattr.lengths[i];
|
|
count_keys++;
|
|
} else {
|
|
gossip_debug(GOSSIP_XATTR_DEBUG, "[RESERVED] key %d -> %s\n",
|
|
i, new_op->downcall.resp.listxattr.key +
|
|
key_size);
|
|
}
|
|
key_size += new_op->downcall.resp.listxattr.lengths[i];
|
|
}
|
|
|
|
/*
|
|
* Since the buffer was large enough, we might have to continue
|
|
* fetching more keys!
|
|
*/
|
|
token = new_op->downcall.resp.listxattr.token;
|
|
if (token != ORANGEFS_ITERATE_END)
|
|
goto try_again;
|
|
|
|
done:
|
|
gossip_debug(GOSSIP_XATTR_DEBUG, "%s: returning %d"
|
|
" [size of buffer %ld] (filled in %d keys)\n",
|
|
__func__,
|
|
ret ? (int)ret : (int)total,
|
|
(long)size,
|
|
count_keys);
|
|
op_release(new_op);
|
|
if (ret == 0)
|
|
ret = total;
|
|
out_unlock:
|
|
up_read(&orangefs_inode->xattr_sem);
|
|
return ret;
|
|
}
|
|
|
|
static int orangefs_xattr_set_default(const struct xattr_handler *handler,
|
|
struct dentry *unused,
|
|
struct inode *inode,
|
|
const char *name,
|
|
const void *buffer,
|
|
size_t size,
|
|
int flags)
|
|
{
|
|
return orangefs_inode_setxattr(inode, name, buffer, size, flags);
|
|
}
|
|
|
|
static int orangefs_xattr_get_default(const struct xattr_handler *handler,
|
|
struct dentry *unused,
|
|
struct inode *inode,
|
|
const char *name,
|
|
void *buffer,
|
|
size_t size)
|
|
{
|
|
return orangefs_inode_getxattr(inode, name, buffer, size);
|
|
|
|
}
|
|
|
|
static struct xattr_handler orangefs_xattr_default_handler = {
|
|
.prefix = "", /* match any name => handlers called with full name */
|
|
.get = orangefs_xattr_get_default,
|
|
.set = orangefs_xattr_set_default,
|
|
};
|
|
|
|
const struct xattr_handler *orangefs_xattr_handlers[] = {
|
|
&posix_acl_access_xattr_handler,
|
|
&posix_acl_default_xattr_handler,
|
|
&orangefs_xattr_default_handler,
|
|
NULL
|
|
};
|