^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/ceph/pagelist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "mds_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/ceph/decode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define XATTR_CEPH_PREFIX "ceph."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static int __remove_xattr(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct ceph_inode_xattr *xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static bool ceph_is_valid_xattr(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) return !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * These define virtual xattrs exposing the recursive directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * statistics and layout metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct ceph_vxattr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) size_t name_size; /* strlen(name) + 1 (for '\0') */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ssize_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) bool (*exists_cb)(struct ceph_inode_info *ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define VXATTR_FLAG_READONLY (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define VXATTR_FLAG_HIDDEN (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define VXATTR_FLAG_RSTAT (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* layouts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static bool ceph_vxattrcb_layout_exists(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ceph_file_layout *fl = &ci->i_layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return (fl->stripe_unit > 0 || fl->stripe_count > 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) fl->object_size > 0 || fl->pool_id >= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) rcu_dereference_raw(fl->pool_ns) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static ssize_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct ceph_osd_client *osdc = &fsc->client->osdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ceph_string *pool_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) s64 pool = ci->i_layout.pool_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) const char *pool_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const char *ns_field = " pool_namespace=";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) char buf[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) size_t len, total_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) pool_ns = ceph_try_get_string(ci->i_layout.pool_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dout("ceph_vxattrcb_layout %p\n", &ci->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) down_read(&osdc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (pool_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) len = snprintf(buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "stripe_unit=%u stripe_count=%u object_size=%u pool=",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ci->i_layout.stripe_unit, ci->i_layout.stripe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ci->i_layout.object_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) total_len = len + strlen(pool_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) len = snprintf(buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) "stripe_unit=%u stripe_count=%u object_size=%u pool=%lld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ci->i_layout.stripe_unit, ci->i_layout.stripe_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ci->i_layout.object_size, pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) total_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (pool_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) total_len += strlen(ns_field) + pool_ns->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ret = total_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (size >= total_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) memcpy(val, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ret = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (pool_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) len = strlen(pool_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) memcpy(val + ret, pool_name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (pool_ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) len = strlen(ns_field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) memcpy(val + ret, ns_field, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) memcpy(val + ret, pool_ns->str, pool_ns->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret += pool_ns->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) up_read(&osdc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ceph_put_string(pool_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * The convention with strings in xattrs is that they should not be NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * terminated, since we're returning the length with them. snprintf always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * NULL terminates however, so call it on a temporary buffer and then memcpy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * the result into place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static __printf(3, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int ceph_fmt_xattr(char *val, size_t size, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) char buf[96]; /* NB: reevaluate size if new vxattrs are added */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ret = vsnprintf(buf, size ? sizeof(buf) : 0, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (size && ret + 1 > sizeof(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) WARN_ONCE(true, "Returned length too big (%d)", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ret <= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) memcpy(val, buf, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static ssize_t ceph_vxattrcb_layout_stripe_unit(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return ceph_fmt_xattr(val, size, "%u", ci->i_layout.stripe_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static ssize_t ceph_vxattrcb_layout_stripe_count(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return ceph_fmt_xattr(val, size, "%u", ci->i_layout.stripe_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static ssize_t ceph_vxattrcb_layout_object_size(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return ceph_fmt_xattr(val, size, "%u", ci->i_layout.object_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static ssize_t ceph_vxattrcb_layout_pool(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct ceph_osd_client *osdc = &fsc->client->osdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) s64 pool = ci->i_layout.pool_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) const char *pool_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) down_read(&osdc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (pool_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = strlen(pool_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (ret <= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) memcpy(val, pool_name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = ceph_fmt_xattr(val, size, "%lld", pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) up_read(&osdc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static ssize_t ceph_vxattrcb_layout_pool_namespace(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct ceph_string *ns = ceph_try_get_string(ci->i_layout.pool_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ret = ns->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (ret <= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) memcpy(val, ns->str, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ceph_put_string(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static ssize_t ceph_vxattrcb_dir_entries(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return ceph_fmt_xattr(val, size, "%lld", ci->i_files + ci->i_subdirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static ssize_t ceph_vxattrcb_dir_files(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return ceph_fmt_xattr(val, size, "%lld", ci->i_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static ssize_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return ceph_fmt_xattr(val, size, "%lld", ci->i_subdirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static ssize_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return ceph_fmt_xattr(val, size, "%lld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ci->i_rfiles + ci->i_rsubdirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static ssize_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return ceph_fmt_xattr(val, size, "%lld", ci->i_rfiles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static ssize_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return ceph_fmt_xattr(val, size, "%lld", ci->i_rsubdirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static ssize_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return ceph_fmt_xattr(val, size, "%lld", ci->i_rbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static ssize_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return ceph_fmt_xattr(val, size, "%lld.%09ld", ci->i_rctime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ci->i_rctime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* dir pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static bool ceph_vxattrcb_dir_pin_exists(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return ci->i_dir_pin != -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static ssize_t ceph_vxattrcb_dir_pin(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return ceph_fmt_xattr(val, size, "%d", (int)ci->i_dir_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* quotas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static bool ceph_vxattrcb_quota_exists(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if ((ci->i_max_files || ci->i_max_bytes) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ci->i_vino.snap == CEPH_NOSNAP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ci->i_snap_realm &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ci->i_snap_realm->ino == ci->i_vino.ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static ssize_t ceph_vxattrcb_quota(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return ceph_fmt_xattr(val, size, "max_bytes=%llu max_files=%llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ci->i_max_bytes, ci->i_max_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static ssize_t ceph_vxattrcb_quota_max_bytes(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return ceph_fmt_xattr(val, size, "%llu", ci->i_max_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static ssize_t ceph_vxattrcb_quota_max_files(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) char *val, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return ceph_fmt_xattr(val, size, "%llu", ci->i_max_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* snapshots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static bool ceph_vxattrcb_snap_btime_exists(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return (ci->i_snap_btime.tv_sec != 0 || ci->i_snap_btime.tv_nsec != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static ssize_t ceph_vxattrcb_snap_btime(struct ceph_inode_info *ci, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return ceph_fmt_xattr(val, size, "%lld.%09ld", ci->i_snap_btime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ci->i_snap_btime.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #define CEPH_XATTR_NAME2(_type, _name, _name2) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) XATTR_CEPH_PREFIX #_type "." #_name "." #_name2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #define XATTR_NAME_CEPH(_type, _name, _flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .name = CEPH_XATTR_NAME(_type, _name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .exists_cb = NULL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .flags = (VXATTR_FLAG_READONLY | _flags), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #define XATTR_RSTAT_FIELD(_type, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) XATTR_NAME_CEPH(_type, _name, VXATTR_FLAG_RSTAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define XATTR_LAYOUT_FIELD(_type, _name, _field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .name = CEPH_XATTR_NAME2(_type, _name, _field), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .name_size = sizeof (CEPH_XATTR_NAME2(_type, _name, _field)), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .getxattr_cb = ceph_vxattrcb_ ## _name ## _ ## _field, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .exists_cb = ceph_vxattrcb_layout_exists, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .flags = VXATTR_FLAG_HIDDEN, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define XATTR_QUOTA_FIELD(_type, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .name = CEPH_XATTR_NAME(_type, _name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .name_size = sizeof(CEPH_XATTR_NAME(_type, _name)), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .exists_cb = ceph_vxattrcb_quota_exists, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .flags = VXATTR_FLAG_HIDDEN, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static struct ceph_vxattr ceph_dir_vxattrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .name = "ceph.dir.layout",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .name_size = sizeof("ceph.dir.layout"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .getxattr_cb = ceph_vxattrcb_layout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .exists_cb = ceph_vxattrcb_layout_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .flags = VXATTR_FLAG_HIDDEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) XATTR_LAYOUT_FIELD(dir, layout, stripe_unit),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) XATTR_LAYOUT_FIELD(dir, layout, stripe_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) XATTR_LAYOUT_FIELD(dir, layout, object_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) XATTR_LAYOUT_FIELD(dir, layout, pool),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) XATTR_LAYOUT_FIELD(dir, layout, pool_namespace),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) XATTR_NAME_CEPH(dir, entries, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) XATTR_NAME_CEPH(dir, files, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) XATTR_NAME_CEPH(dir, subdirs, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) XATTR_RSTAT_FIELD(dir, rentries),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) XATTR_RSTAT_FIELD(dir, rfiles),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) XATTR_RSTAT_FIELD(dir, rsubdirs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) XATTR_RSTAT_FIELD(dir, rbytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) XATTR_RSTAT_FIELD(dir, rctime),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .name = "ceph.dir.pin",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .name_size = sizeof("ceph.dir.pin"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .getxattr_cb = ceph_vxattrcb_dir_pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .exists_cb = ceph_vxattrcb_dir_pin_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .flags = VXATTR_FLAG_HIDDEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .name = "ceph.quota",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .name_size = sizeof("ceph.quota"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .getxattr_cb = ceph_vxattrcb_quota,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .exists_cb = ceph_vxattrcb_quota_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .flags = VXATTR_FLAG_HIDDEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) XATTR_QUOTA_FIELD(quota, max_bytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) XATTR_QUOTA_FIELD(quota, max_files),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .name = "ceph.snap.btime",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .name_size = sizeof("ceph.snap.btime"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) .getxattr_cb = ceph_vxattrcb_snap_btime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .exists_cb = ceph_vxattrcb_snap_btime_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) .flags = VXATTR_FLAG_READONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) { .name = NULL, 0 } /* Required table terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static struct ceph_vxattr ceph_file_vxattrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .name = "ceph.file.layout",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .name_size = sizeof("ceph.file.layout"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .getxattr_cb = ceph_vxattrcb_layout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .exists_cb = ceph_vxattrcb_layout_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .flags = VXATTR_FLAG_HIDDEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) XATTR_LAYOUT_FIELD(file, layout, stripe_unit),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) XATTR_LAYOUT_FIELD(file, layout, stripe_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) XATTR_LAYOUT_FIELD(file, layout, object_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) XATTR_LAYOUT_FIELD(file, layout, pool),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) XATTR_LAYOUT_FIELD(file, layout, pool_namespace),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .name = "ceph.snap.btime",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .name_size = sizeof("ceph.snap.btime"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .getxattr_cb = ceph_vxattrcb_snap_btime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .exists_cb = ceph_vxattrcb_snap_btime_exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .flags = VXATTR_FLAG_READONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) { .name = NULL, 0 } /* Required table terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return ceph_dir_vxattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) else if (S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return ceph_file_vxattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct ceph_vxattr *vxattr = ceph_inode_vxattrs(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (vxattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) while (vxattr->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!strcmp(vxattr->name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return vxattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) vxattr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static int __set_xattr(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) const char *name, int name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) const char *val, int val_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int flags, int update_xattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct ceph_inode_xattr **newxattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct rb_node **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int new = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) p = &ci->i_xattrs.index.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) xattr = rb_entry(parent, struct ceph_inode_xattr, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) c = strncmp(name, xattr->name, min(name_len, xattr->name_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (c < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) p = &(*p)->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) else if (c > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) p = &(*p)->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (name_len == xattr->name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) else if (name_len < xattr->name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) p = &(*p)->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) p = &(*p)->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (update_xattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (xattr && (flags & XATTR_CREATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) else if (!xattr && (flags & XATTR_REPLACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) kfree(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) kfree(*newxattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (update_xattr < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) __remove_xattr(ci, xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) kfree(*newxattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (!xattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) new = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) xattr = *newxattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) xattr->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) xattr->name_len = name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) xattr->should_free_name = update_xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ci->i_xattrs.count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) dout("__set_xattr count=%d\n", ci->i_xattrs.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) kfree(*newxattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) *newxattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (xattr->should_free_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) kfree(xattr->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (update_xattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) name = xattr->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) ci->i_xattrs.names_size -= xattr->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ci->i_xattrs.vals_size -= xattr->val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ci->i_xattrs.names_size += name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) ci->i_xattrs.vals_size += val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) xattr->val = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) xattr->val = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) xattr->val_len = val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) xattr->dirty = update_xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) xattr->should_free_val = (val && update_xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) rb_link_node(&xattr->node, parent, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) rb_insert_color(&xattr->node, &ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) dout("__set_xattr_val p=%p\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) dout("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) ceph_vinop(&ci->vfs_inode), xattr, name_len, name, val_len, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct rb_node **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct rb_node *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) int name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) p = &ci->i_xattrs.index.rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) xattr = rb_entry(parent, struct ceph_inode_xattr, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) c = strncmp(name, xattr->name, xattr->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (c == 0 && name_len > xattr->name_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) c = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (c < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) p = &(*p)->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) else if (c > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) p = &(*p)->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dout("__get_xattr %s: found %.*s\n", name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) xattr->val_len, xattr->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) dout("__get_xattr %s: not found\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static void __free_xattr(struct ceph_inode_xattr *xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) BUG_ON(!xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (xattr->should_free_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) kfree(xattr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (xattr->should_free_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) kfree(xattr->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) kfree(xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static int __remove_xattr(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct ceph_inode_xattr *xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) rb_erase(&xattr->node, &ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (xattr->should_free_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) kfree(xattr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (xattr->should_free_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) kfree(xattr->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) ci->i_xattrs.names_size -= xattr->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ci->i_xattrs.vals_size -= xattr->val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) ci->i_xattrs.count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) kfree(xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static char *__copy_xattr_names(struct ceph_inode_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) char *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) p = rb_first(&ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) dout("__copy_xattr_names count=%d\n", ci->i_xattrs.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) while (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) xattr = rb_entry(p, struct ceph_inode_xattr, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) memcpy(dest, xattr->name, xattr->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) dest[xattr->name_len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) dout("dest=%s %p (%s) (%d/%d)\n", dest, xattr, xattr->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) xattr->name_len, ci->i_xattrs.names_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) dest += xattr->name_len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) p = rb_next(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct rb_node *p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) p = rb_first(&ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) dout("__ceph_destroy_xattrs p=%p\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) while (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) xattr = rb_entry(p, struct ceph_inode_xattr, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) tmp = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) p = rb_next(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) xattr->name_len, xattr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) rb_erase(tmp, &ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) __free_xattr(xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) ci->i_xattrs.names_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) ci->i_xattrs.vals_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) ci->i_xattrs.index_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ci->i_xattrs.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) ci->i_xattrs.index = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static int __build_xattrs(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) __releases(ci->i_ceph_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) __acquires(ci->i_ceph_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) u32 namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) u32 numattr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) void *p, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) const char *name, *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct ceph_inode_info *ci = ceph_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) u64 xattr_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct ceph_inode_xattr **xattrs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) dout("__build_xattrs() len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ci->i_xattrs.blob ? (int)ci->i_xattrs.blob->vec.iov_len : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (ci->i_xattrs.index_version >= ci->i_xattrs.version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return 0; /* already built */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) __ceph_destroy_xattrs(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* updated internal xattr rb tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (ci->i_xattrs.blob && ci->i_xattrs.blob->vec.iov_len > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) p = ci->i_xattrs.blob->vec.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) end = p + ci->i_xattrs.blob->vec.iov_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) ceph_decode_32_safe(&p, end, numattr, bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) xattr_version = ci->i_xattrs.version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) xattrs = kcalloc(numattr, sizeof(struct ceph_inode_xattr *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (!xattrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto bad_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) for (i = 0; i < numattr; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) xattrs[i] = kmalloc(sizeof(struct ceph_inode_xattr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (!xattrs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) goto bad_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (ci->i_xattrs.version != xattr_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* lost a race, retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) for (i = 0; i < numattr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) kfree(xattrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) kfree(xattrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) xattrs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) while (numattr--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) ceph_decode_32_safe(&p, end, len, bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) namelen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) name = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) p += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) ceph_decode_32_safe(&p, end, len, bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) val = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) p += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) err = __set_xattr(ci, name, namelen, val, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 0, 0, &xattrs[numattr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) kfree(xattrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) ci->i_xattrs.index_version = ci->i_xattrs.version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) ci->i_xattrs.dirty = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) bad_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (xattrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) for (i = 0; i < numattr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) kfree(xattrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) kfree(xattrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) ci->i_xattrs.names_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static int __get_required_blob_size(struct ceph_inode_info *ci, int name_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int val_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * 4 bytes for the length, and additional 4 bytes per each xattr name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * 4 bytes per each value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) int size = 4 + ci->i_xattrs.count*(4 + 4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) ci->i_xattrs.names_size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) ci->i_xattrs.vals_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) ci->i_xattrs.count, ci->i_xattrs.names_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) ci->i_xattrs.vals_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (name_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) size += 4 + 4 + name_size + val_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * If there are dirty xattrs, reencode xattrs into the prealloc_blob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * and swap into place. It returns the old i_xattrs.blob (or NULL) so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * that it can be freed by the caller as the i_ceph_lock is likely to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct ceph_buffer *__ceph_build_xattrs_blob(struct ceph_inode_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct ceph_buffer *old_blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) void *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) dout("__build_xattrs_blob %p\n", &ci->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (ci->i_xattrs.dirty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int need = __get_required_blob_size(ci, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) BUG_ON(need > ci->i_xattrs.prealloc_blob->alloc_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) p = rb_first(&ci->i_xattrs.index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) dest = ci->i_xattrs.prealloc_blob->vec.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) ceph_encode_32(&dest, ci->i_xattrs.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) while (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) xattr = rb_entry(p, struct ceph_inode_xattr, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ceph_encode_32(&dest, xattr->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) memcpy(dest, xattr->name, xattr->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) dest += xattr->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) ceph_encode_32(&dest, xattr->val_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) memcpy(dest, xattr->val, xattr->val_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) dest += xattr->val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) p = rb_next(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) /* adjust buffer len; it may be larger than we need */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) ci->i_xattrs.prealloc_blob->vec.iov_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (ci->i_xattrs.blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) old_blob = ci->i_xattrs.blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) ci->i_xattrs.prealloc_blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) ci->i_xattrs.dirty = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) ci->i_xattrs.version++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return old_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) static inline int __get_request_mask(struct inode *in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct ceph_mds_request *req = current->journal_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (req && req->r_target_inode == in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (req->r_op == CEPH_MDS_OP_LOOKUP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) req->r_op == CEPH_MDS_OP_LOOKUPINO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) req->r_op == CEPH_MDS_OP_LOOKUPPARENT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) req->r_op == CEPH_MDS_OP_GETATTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) mask = le32_to_cpu(req->r_args.getattr.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) } else if (req->r_op == CEPH_MDS_OP_OPEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) req->r_op == CEPH_MDS_OP_CREATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) mask = le32_to_cpu(req->r_args.open.mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct ceph_inode_info *ci = ceph_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) struct ceph_inode_xattr *xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct ceph_vxattr *vxattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) int req_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) /* let's see if a virtual xattr was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) vxattr = ceph_match_vxattr(inode, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (vxattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) int mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (vxattr->flags & VXATTR_FLAG_RSTAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) mask |= CEPH_STAT_RSTAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) err = ceph_do_getattr(inode, mask, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (!(vxattr->exists_cb && !vxattr->exists_cb(ci))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) err = vxattr->getxattr_cb(ci, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) if (size && size < err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) req_mask = __get_request_mask(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) dout("getxattr %p name '%s' ver=%lld index_ver=%lld\n", inode, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) ci->i_xattrs.version, ci->i_xattrs.index_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (ci->i_xattrs.version == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) !((req_mask & CEPH_CAP_XATTR_SHARED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) __ceph_caps_issued_mask_metric(ci, CEPH_CAP_XATTR_SHARED, 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* security module gets xattr while filling trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (current->journal_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) pr_warn_ratelimited("sync getxattr %p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) "during filling trace\n", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /* get xattrs from mds (if we don't already have them) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) err = __build_xattrs(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) err = -ENODATA; /* == ENOATTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) xattr = __get_xattr(ci, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (!xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (size && size < xattr->val_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) err = xattr->val_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) memcpy(value, xattr->val, xattr->val_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (current->journal_info &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) security_ismaclabel(name + XATTR_SECURITY_PREFIX_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) ci->i_ceph_flags |= CEPH_I_SEC_INITED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) struct ceph_inode_info *ci = ceph_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) bool len_only = (size == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) u32 namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) dout("listxattr %p ver=%lld index_ver=%lld\n", inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) ci->i_xattrs.version, ci->i_xattrs.index_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (ci->i_xattrs.version == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) !__ceph_caps_issued_mask_metric(ci, CEPH_CAP_XATTR_SHARED, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) err = __build_xattrs(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) /* add 1 byte for each xattr due to the null termination */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) namelen = ci->i_xattrs.names_size + ci->i_xattrs.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (!len_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (namelen > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) names = __copy_xattr_names(ci, names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) size -= namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) err = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) static int ceph_sync_setxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) const char *value, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) struct ceph_inode_info *ci = ceph_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) struct ceph_mds_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) struct ceph_mds_client *mdsc = fsc->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct ceph_pagelist *pagelist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) int op = CEPH_MDS_OP_SETXATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /* copy value into pagelist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) pagelist = ceph_pagelist_alloc(GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (!pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) err = ceph_pagelist_append(pagelist, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) } else if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (flags & CEPH_XATTR_REPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) op = CEPH_MDS_OP_RMXATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) flags |= CEPH_XATTR_REMOVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) dout("setxattr value=%.*s\n", (int)size, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) /* do request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (IS_ERR(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) err = PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) req->r_path2 = kstrdup(name, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!req->r_path2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) if (op == CEPH_MDS_OP_SETXATTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) req->r_args.setxattr.flags = cpu_to_le32(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) req->r_pagelist = pagelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) pagelist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) req->r_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) req->r_num_caps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) dout("xattr.ver (before): %lld\n", ci->i_xattrs.version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) err = ceph_mdsc_do_request(mdsc, NULL, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) ceph_mdsc_put_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) dout("xattr.ver (after): %lld\n", ci->i_xattrs.version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) ceph_pagelist_release(pagelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) int __ceph_setxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) const void *value, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct ceph_vxattr *vxattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct ceph_inode_info *ci = ceph_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) struct ceph_cap_flush *prealloc_cf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) struct ceph_buffer *old_blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) int issued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) int dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) int name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) int val_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) char *newname = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) char *newval = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct ceph_inode_xattr *xattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) int required_blob_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) bool check_realm = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) bool lock_snap_rwsem = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) if (ceph_snap(inode) != CEPH_NOSNAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) vxattr = ceph_match_vxattr(inode, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (vxattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (vxattr->flags & VXATTR_FLAG_READONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (value && !strncmp(vxattr->name, "ceph.quota", 10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) check_realm = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) /* pass any unhandled ceph.* xattrs through to the MDS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) goto do_sync_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) /* preallocate memory for xattr name, value, index node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) newname = kmemdup(name, name_len + 1, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (!newname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (val_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) newval = kmemdup(value, val_len, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (!newval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (!xattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) prealloc_cf = ceph_alloc_cap_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (!prealloc_cf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) issued = __ceph_caps_issued(ci, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) goto do_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (!lock_snap_rwsem && !ci->i_head_snapc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) lock_snap_rwsem = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) if (!down_read_trylock(&mdsc->snap_rwsem)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) down_read(&mdsc->snap_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) dout("setxattr %p name '%s' issued %s\n", inode, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) ceph_cap_string(issued));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) __build_xattrs(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) required_blob_size = __get_required_blob_size(ci, name_len, val_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (!ci->i_xattrs.prealloc_blob ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct ceph_buffer *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) ceph_buffer_put(old_blob); /* Shouldn't be required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) dout(" pre-allocating new blob size=%d\n", required_blob_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if (!blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) goto do_sync_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /* prealloc_blob can't be released while holding i_ceph_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (ci->i_xattrs.prealloc_blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) old_blob = ci->i_xattrs.prealloc_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) ci->i_xattrs.prealloc_blob = blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) err = __set_xattr(ci, newname, name_len, newval, val_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) flags, value ? 1 : -1, &xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) &prealloc_cf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) ci->i_xattrs.dirty = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) ceph_buffer_put(old_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (lock_snap_rwsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) up_read(&mdsc->snap_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) __mark_inode_dirty(inode, dirty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) ceph_free_cap_flush(prealloc_cf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) do_sync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) do_sync_unlocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) if (lock_snap_rwsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) up_read(&mdsc->snap_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /* security module set xattr while filling trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (current->journal_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) pr_warn_ratelimited("sync setxattr %p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) "during filling trace\n", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) err = ceph_sync_setxattr(inode, name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if (err >= 0 && check_realm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /* check if snaprealm was created for quota inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if ((ci->i_max_files || ci->i_max_bytes) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) !(ci->i_snap_realm &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) ci->i_snap_realm->ino == ci->i_vino.ino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) ceph_free_cap_flush(prealloc_cf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) kfree(newname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) kfree(newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) kfree(xattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) static int ceph_get_xattr_handler(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) struct dentry *dentry, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) const char *name, void *value, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (!ceph_is_valid_xattr(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return __ceph_getxattr(inode, name, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static int ceph_set_xattr_handler(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) struct dentry *unused, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) const char *name, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (!ceph_is_valid_xattr(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) return __ceph_setxattr(inode, name, value, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) static const struct xattr_handler ceph_other_xattr_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) .prefix = "", /* match any name => handlers called with full name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) .get = ceph_get_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) .set = ceph_set_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) #ifdef CONFIG_SECURITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) bool ceph_security_xattr_wanted(struct inode *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) return in->i_security != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) bool ceph_security_xattr_deadlock(struct inode *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) struct ceph_inode_info *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (!in->i_security)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) ci = ceph_inode(in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) spin_lock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) ret = !(ci->i_ceph_flags & CEPH_I_SEC_INITED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) !(ci->i_xattrs.version > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) __ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) spin_unlock(&ci->i_ceph_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) #ifdef CONFIG_CEPH_FS_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) struct ceph_acl_sec_ctx *as_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) struct ceph_pagelist *pagelist = as_ctx->pagelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) size_t name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) err = security_dentry_init_security(dentry, mode, &dentry->d_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) &as_ctx->sec_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) &as_ctx->sec_ctxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) WARN_ON_ONCE(err != -EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) err = 0; /* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) if (!pagelist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) pagelist = ceph_pagelist_alloc(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (!pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) err = ceph_pagelist_reserve(pagelist, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) ceph_pagelist_encode_32(pagelist, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) * FIXME: Make security_dentry_init_security() generic. Currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) * It only supports single security module and only selinux has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) * dentry_init_security hook.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) name = XATTR_NAME_SELINUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) name_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) err = ceph_pagelist_reserve(pagelist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 4 * 2 + name_len + as_ctx->sec_ctxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (as_ctx->pagelist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) /* update count of KV pairs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) BUG_ON(pagelist->length <= sizeof(__le32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (list_is_singular(&pagelist->head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) le32_add_cpu((__le32*)pagelist->mapped_tail, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct page *page = list_first_entry(&pagelist->head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) struct page, lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) void *addr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) le32_add_cpu((__le32*)addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) kunmap_atomic(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) as_ctx->pagelist = pagelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) ceph_pagelist_encode_32(pagelist, name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) ceph_pagelist_append(pagelist, name, name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) ceph_pagelist_encode_32(pagelist, as_ctx->sec_ctxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) ceph_pagelist_append(pagelist, as_ctx->sec_ctx, as_ctx->sec_ctxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) if (pagelist && !as_ctx->pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) ceph_pagelist_release(pagelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) #endif /* CONFIG_CEPH_FS_SECURITY_LABEL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) #endif /* CONFIG_SECURITY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) void ceph_release_acl_sec_ctx(struct ceph_acl_sec_ctx *as_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) #ifdef CONFIG_CEPH_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) posix_acl_release(as_ctx->acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) posix_acl_release(as_ctx->default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) #ifdef CONFIG_CEPH_FS_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) security_release_secctx(as_ctx->sec_ctx, as_ctx->sec_ctxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if (as_ctx->pagelist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) ceph_pagelist_release(as_ctx->pagelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) * List of handlers for synthetic system.* attributes. Other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) * attributes are handled directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) const struct xattr_handler *ceph_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) #ifdef CONFIG_CEPH_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) &ceph_other_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) };