1 #include <linux/ceph/ceph_debug.h>
4 #include "mds_client.h"
6 #include <linux/ceph/decode.h>
8 #include <linux/xattr.h>
9 #include <linux/slab.h>
11 #define XATTR_CEPH_PREFIX "ceph."
12 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
14 static bool ceph_is_valid_xattr(const char *name)
16 return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
17 !strncmp(name, XATTR_SECURITY_PREFIX,
18 XATTR_SECURITY_PREFIX_LEN) ||
19 !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
20 !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
24 * These define virtual xattrs exposing the recursive directory
25 * statistics and layout metadata.
29 size_t name_size; /* strlen(name) + 1 (for '\0') */
30 size_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
32 bool readonly, hidden;
33 bool (*exists_cb)(struct ceph_inode_info *ci);
38 static bool ceph_vxattrcb_layout_exists(struct ceph_inode_info *ci)
41 char *p = (char *)&ci->i_layout;
43 for (s = 0; s < sizeof(ci->i_layout); s++, p++)
49 static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
53 struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb);
54 struct ceph_osd_client *osdc = &fsc->client->osdc;
55 s64 pool = ceph_file_layout_pg_pool(ci->i_layout);
56 const char *pool_name;
58 dout("ceph_vxattrcb_layout %p\n", &ci->vfs_inode);
59 down_read(&osdc->map_sem);
60 pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
62 ret = snprintf(val, size,
63 "stripe_unit=%lld stripe_count=%lld object_size=%lld pool=%s",
64 (unsigned long long)ceph_file_layout_su(ci->i_layout),
65 (unsigned long long)ceph_file_layout_stripe_count(ci->i_layout),
66 (unsigned long long)ceph_file_layout_object_size(ci->i_layout),
69 ret = snprintf(val, size,
70 "stripe_unit=%lld stripe_count=%lld object_size=%lld pool=%lld",
71 (unsigned long long)ceph_file_layout_su(ci->i_layout),
72 (unsigned long long)ceph_file_layout_stripe_count(ci->i_layout),
73 (unsigned long long)ceph_file_layout_object_size(ci->i_layout),
74 (unsigned long long)pool);
76 up_read(&osdc->map_sem);
82 static size_t ceph_vxattrcb_dir_entries(struct ceph_inode_info *ci, char *val,
85 return snprintf(val, size, "%lld", ci->i_files + ci->i_subdirs);
88 static size_t ceph_vxattrcb_dir_files(struct ceph_inode_info *ci, char *val,
91 return snprintf(val, size, "%lld", ci->i_files);
94 static size_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info *ci, char *val,
97 return snprintf(val, size, "%lld", ci->i_subdirs);
100 static size_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info *ci, char *val,
103 return snprintf(val, size, "%lld", ci->i_rfiles + ci->i_rsubdirs);
106 static size_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info *ci, char *val,
109 return snprintf(val, size, "%lld", ci->i_rfiles);
112 static size_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info *ci, char *val,
115 return snprintf(val, size, "%lld", ci->i_rsubdirs);
118 static size_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info *ci, char *val,
121 return snprintf(val, size, "%lld", ci->i_rbytes);
124 static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
127 return snprintf(val, size, "%ld.09%ld", (long)ci->i_rctime.tv_sec,
128 (long)ci->i_rctime.tv_nsec);
132 #define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
134 #define XATTR_NAME_CEPH(_type, _name) \
136 .name = CEPH_XATTR_NAME(_type, _name), \
137 .name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
138 .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
144 static struct ceph_vxattr ceph_dir_vxattrs[] = {
145 XATTR_NAME_CEPH(dir, entries),
146 XATTR_NAME_CEPH(dir, files),
147 XATTR_NAME_CEPH(dir, subdirs),
148 XATTR_NAME_CEPH(dir, rentries),
149 XATTR_NAME_CEPH(dir, rfiles),
150 XATTR_NAME_CEPH(dir, rsubdirs),
151 XATTR_NAME_CEPH(dir, rbytes),
152 XATTR_NAME_CEPH(dir, rctime),
153 { 0 } /* Required table terminator */
155 static size_t ceph_dir_vxattrs_name_size; /* total size of all names */
159 static struct ceph_vxattr ceph_file_vxattrs[] = {
161 .name = "ceph.file.layout",
162 .name_size = sizeof("ceph.file.layout"),
163 .getxattr_cb = ceph_vxattrcb_layout,
166 .exists_cb = ceph_vxattrcb_layout_exists,
168 { 0 } /* Required table terminator */
170 static size_t ceph_file_vxattrs_name_size; /* total size of all names */
172 static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
174 if (S_ISDIR(inode->i_mode))
175 return ceph_dir_vxattrs;
176 else if (S_ISREG(inode->i_mode))
177 return ceph_file_vxattrs;
181 static size_t ceph_vxattrs_name_size(struct ceph_vxattr *vxattrs)
183 if (vxattrs == ceph_dir_vxattrs)
184 return ceph_dir_vxattrs_name_size;
185 if (vxattrs == ceph_file_vxattrs)
186 return ceph_file_vxattrs_name_size;
193 * Compute the aggregate size (including terminating '\0') of all
194 * virtual extended attribute names in the given vxattr table.
196 static size_t __init vxattrs_name_size(struct ceph_vxattr *vxattrs)
198 struct ceph_vxattr *vxattr;
201 for (vxattr = vxattrs; vxattr->name; vxattr++)
203 size += vxattr->name_size;
208 /* Routines called at initialization and exit time */
210 void __init ceph_xattr_init(void)
212 ceph_dir_vxattrs_name_size = vxattrs_name_size(ceph_dir_vxattrs);
213 ceph_file_vxattrs_name_size = vxattrs_name_size(ceph_file_vxattrs);
216 void ceph_xattr_exit(void)
218 ceph_dir_vxattrs_name_size = 0;
219 ceph_file_vxattrs_name_size = 0;
222 static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
225 struct ceph_vxattr *vxattr = ceph_inode_vxattrs(inode);
228 while (vxattr->name) {
229 if (!strcmp(vxattr->name, name))
238 static int __set_xattr(struct ceph_inode_info *ci,
239 const char *name, int name_len,
240 const char *val, int val_len,
242 int should_free_name, int should_free_val,
243 struct ceph_inode_xattr **newxattr)
246 struct rb_node *parent = NULL;
247 struct ceph_inode_xattr *xattr = NULL;
251 p = &ci->i_xattrs.index.rb_node;
254 xattr = rb_entry(parent, struct ceph_inode_xattr, node);
255 c = strncmp(name, xattr->name, min(name_len, xattr->name_len));
261 if (name_len == xattr->name_len)
263 else if (name_len < xattr->name_len)
275 xattr->name_len = name_len;
276 xattr->should_free_name = should_free_name;
278 ci->i_xattrs.count++;
279 dout("__set_xattr count=%d\n", ci->i_xattrs.count);
283 if (xattr->should_free_val)
284 kfree((void *)xattr->val);
286 if (should_free_name) {
290 ci->i_xattrs.names_size -= xattr->name_len;
291 ci->i_xattrs.vals_size -= xattr->val_len;
293 ci->i_xattrs.names_size += name_len;
294 ci->i_xattrs.vals_size += val_len;
300 xattr->val_len = val_len;
301 xattr->dirty = dirty;
302 xattr->should_free_val = (val && should_free_val);
305 rb_link_node(&xattr->node, parent, p);
306 rb_insert_color(&xattr->node, &ci->i_xattrs.index);
307 dout("__set_xattr_val p=%p\n", p);
310 dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
311 ceph_vinop(&ci->vfs_inode), xattr, name, val_len, val);
316 static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,
320 struct rb_node *parent = NULL;
321 struct ceph_inode_xattr *xattr = NULL;
322 int name_len = strlen(name);
325 p = &ci->i_xattrs.index.rb_node;
328 xattr = rb_entry(parent, struct ceph_inode_xattr, node);
329 c = strncmp(name, xattr->name, xattr->name_len);
330 if (c == 0 && name_len > xattr->name_len)
337 dout("__get_xattr %s: found %.*s\n", name,
338 xattr->val_len, xattr->val);
343 dout("__get_xattr %s: not found\n", name);
348 static void __free_xattr(struct ceph_inode_xattr *xattr)
352 if (xattr->should_free_name)
353 kfree((void *)xattr->name);
354 if (xattr->should_free_val)
355 kfree((void *)xattr->val);
360 static int __remove_xattr(struct ceph_inode_info *ci,
361 struct ceph_inode_xattr *xattr)
366 rb_erase(&xattr->node, &ci->i_xattrs.index);
368 if (xattr->should_free_name)
369 kfree((void *)xattr->name);
370 if (xattr->should_free_val)
371 kfree((void *)xattr->val);
373 ci->i_xattrs.names_size -= xattr->name_len;
374 ci->i_xattrs.vals_size -= xattr->val_len;
375 ci->i_xattrs.count--;
381 static int __remove_xattr_by_name(struct ceph_inode_info *ci,
385 struct ceph_inode_xattr *xattr;
388 p = &ci->i_xattrs.index.rb_node;
389 xattr = __get_xattr(ci, name);
390 err = __remove_xattr(ci, xattr);
394 static char *__copy_xattr_names(struct ceph_inode_info *ci,
398 struct ceph_inode_xattr *xattr = NULL;
400 p = rb_first(&ci->i_xattrs.index);
401 dout("__copy_xattr_names count=%d\n", ci->i_xattrs.count);
404 xattr = rb_entry(p, struct ceph_inode_xattr, node);
405 memcpy(dest, xattr->name, xattr->name_len);
406 dest[xattr->name_len] = '\0';
408 dout("dest=%s %p (%s) (%d/%d)\n", dest, xattr, xattr->name,
409 xattr->name_len, ci->i_xattrs.names_size);
411 dest += xattr->name_len + 1;
418 void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
420 struct rb_node *p, *tmp;
421 struct ceph_inode_xattr *xattr = NULL;
423 p = rb_first(&ci->i_xattrs.index);
425 dout("__ceph_destroy_xattrs p=%p\n", p);
428 xattr = rb_entry(p, struct ceph_inode_xattr, node);
431 dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p,
432 xattr->name_len, xattr->name);
433 rb_erase(tmp, &ci->i_xattrs.index);
438 ci->i_xattrs.names_size = 0;
439 ci->i_xattrs.vals_size = 0;
440 ci->i_xattrs.index_version = 0;
441 ci->i_xattrs.count = 0;
442 ci->i_xattrs.index = RB_ROOT;
445 static int __build_xattrs(struct inode *inode)
446 __releases(ci->i_ceph_lock)
447 __acquires(ci->i_ceph_lock)
453 const char *name, *val;
454 struct ceph_inode_info *ci = ceph_inode(inode);
456 struct ceph_inode_xattr **xattrs = NULL;
460 dout("__build_xattrs() len=%d\n",
461 ci->i_xattrs.blob ? (int)ci->i_xattrs.blob->vec.iov_len : 0);
463 if (ci->i_xattrs.index_version >= ci->i_xattrs.version)
464 return 0; /* already built */
466 __ceph_destroy_xattrs(ci);
469 /* updated internal xattr rb tree */
470 if (ci->i_xattrs.blob && ci->i_xattrs.blob->vec.iov_len > 4) {
471 p = ci->i_xattrs.blob->vec.iov_base;
472 end = p + ci->i_xattrs.blob->vec.iov_len;
473 ceph_decode_32_safe(&p, end, numattr, bad);
474 xattr_version = ci->i_xattrs.version;
475 spin_unlock(&ci->i_ceph_lock);
477 xattrs = kcalloc(numattr, sizeof(struct ceph_xattr *),
482 memset(xattrs, 0, numattr*sizeof(struct ceph_xattr *));
483 for (i = 0; i < numattr; i++) {
484 xattrs[i] = kmalloc(sizeof(struct ceph_inode_xattr),
490 spin_lock(&ci->i_ceph_lock);
491 if (ci->i_xattrs.version != xattr_version) {
492 /* lost a race, retry */
493 for (i = 0; i < numattr; i++)
501 ceph_decode_32_safe(&p, end, len, bad);
505 ceph_decode_32_safe(&p, end, len, bad);
509 err = __set_xattr(ci, name, namelen, val, len,
510 0, 0, 0, &xattrs[numattr]);
517 ci->i_xattrs.index_version = ci->i_xattrs.version;
518 ci->i_xattrs.dirty = false;
522 spin_lock(&ci->i_ceph_lock);
525 for (i = 0; i < numattr; i++)
529 ci->i_xattrs.names_size = 0;
533 static int __get_required_blob_size(struct ceph_inode_info *ci, int name_size,
537 * 4 bytes for the length, and additional 4 bytes per each xattr name,
538 * 4 bytes per each value
540 int size = 4 + ci->i_xattrs.count*(4 + 4) +
541 ci->i_xattrs.names_size +
542 ci->i_xattrs.vals_size;
543 dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
544 ci->i_xattrs.count, ci->i_xattrs.names_size,
545 ci->i_xattrs.vals_size);
548 size += 4 + 4 + name_size + val_size;
554 * If there are dirty xattrs, reencode xattrs into the prealloc_blob
555 * and swap into place.
557 void __ceph_build_xattrs_blob(struct ceph_inode_info *ci)
560 struct ceph_inode_xattr *xattr = NULL;
563 dout("__build_xattrs_blob %p\n", &ci->vfs_inode);
564 if (ci->i_xattrs.dirty) {
565 int need = __get_required_blob_size(ci, 0, 0);
567 BUG_ON(need > ci->i_xattrs.prealloc_blob->alloc_len);
569 p = rb_first(&ci->i_xattrs.index);
570 dest = ci->i_xattrs.prealloc_blob->vec.iov_base;
572 ceph_encode_32(&dest, ci->i_xattrs.count);
574 xattr = rb_entry(p, struct ceph_inode_xattr, node);
576 ceph_encode_32(&dest, xattr->name_len);
577 memcpy(dest, xattr->name, xattr->name_len);
578 dest += xattr->name_len;
579 ceph_encode_32(&dest, xattr->val_len);
580 memcpy(dest, xattr->val, xattr->val_len);
581 dest += xattr->val_len;
586 /* adjust buffer len; it may be larger than we need */
587 ci->i_xattrs.prealloc_blob->vec.iov_len =
588 dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
590 if (ci->i_xattrs.blob)
591 ceph_buffer_put(ci->i_xattrs.blob);
592 ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
593 ci->i_xattrs.prealloc_blob = NULL;
594 ci->i_xattrs.dirty = false;
595 ci->i_xattrs.version++;
599 ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
602 struct inode *inode = dentry->d_inode;
603 struct ceph_inode_info *ci = ceph_inode(inode);
605 struct ceph_inode_xattr *xattr;
606 struct ceph_vxattr *vxattr = NULL;
608 if (!ceph_is_valid_xattr(name))
611 spin_lock(&ci->i_ceph_lock);
612 dout("getxattr %p ver=%lld index_ver=%lld\n", inode,
613 ci->i_xattrs.version, ci->i_xattrs.index_version);
615 /* let's see if a virtual xattr was requested */
616 vxattr = ceph_match_vxattr(inode, name);
617 if (vxattr && !(vxattr->exists_cb && !vxattr->exists_cb(ci))) {
618 err = vxattr->getxattr_cb(ci, value, size);
622 if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1) &&
623 (ci->i_xattrs.index_version >= ci->i_xattrs.version)) {
626 spin_unlock(&ci->i_ceph_lock);
627 /* get xattrs from mds (if we don't already have them) */
628 err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR);
633 spin_lock(&ci->i_ceph_lock);
635 err = __build_xattrs(inode);
640 err = -ENODATA; /* == ENOATTR */
641 xattr = __get_xattr(ci, name);
646 if (size && size < xattr->val_len)
649 err = xattr->val_len;
653 memcpy(value, xattr->val, xattr->val_len);
656 spin_unlock(&ci->i_ceph_lock);
660 ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
662 struct inode *inode = dentry->d_inode;
663 struct ceph_inode_info *ci = ceph_inode(inode);
664 struct ceph_vxattr *vxattrs = ceph_inode_vxattrs(inode);
671 spin_lock(&ci->i_ceph_lock);
672 dout("listxattr %p ver=%lld index_ver=%lld\n", inode,
673 ci->i_xattrs.version, ci->i_xattrs.index_version);
675 if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1) &&
676 (ci->i_xattrs.index_version >= ci->i_xattrs.version)) {
679 spin_unlock(&ci->i_ceph_lock);
680 err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR);
685 spin_lock(&ci->i_ceph_lock);
687 err = __build_xattrs(inode);
693 * Start with virtual dir xattr names (if any) (including
694 * terminating '\0' characters for each).
696 vir_namelen = ceph_vxattrs_name_size(vxattrs);
698 /* adding 1 byte per each variable due to the null termination */
699 namelen = ci->i_xattrs.names_size + ci->i_xattrs.count;
701 if (size && vir_namelen + namelen > size)
704 err = namelen + vir_namelen;
708 names = __copy_xattr_names(ci, names);
710 /* virtual xattr names, too */
713 for (i = 0; vxattrs[i].name; i++) {
714 if (!vxattrs[i].hidden &&
715 !(vxattrs[i].exists_cb &&
716 !vxattrs[i].exists_cb(ci))) {
717 len = sprintf(names, "%s", vxattrs[i].name);
725 spin_unlock(&ci->i_ceph_lock);
729 static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
730 const char *value, size_t size, int flags)
732 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
733 struct inode *inode = dentry->d_inode;
734 struct ceph_inode_info *ci = ceph_inode(inode);
735 struct inode *parent_inode;
736 struct ceph_mds_request *req;
737 struct ceph_mds_client *mdsc = fsc->mdsc;
740 struct page **pages = NULL;
743 /* copy value into some pages */
744 nr_pages = calc_pages_for(0, size);
746 pages = kmalloc(sizeof(pages[0])*nr_pages, GFP_NOFS);
750 for (i = 0; i < nr_pages; i++) {
751 pages[i] = __page_cache_alloc(GFP_NOFS);
756 kaddr = kmap(pages[i]);
757 memcpy(kaddr, value + i*PAGE_CACHE_SIZE,
758 min(PAGE_CACHE_SIZE, size-i*PAGE_CACHE_SIZE));
762 dout("setxattr value=%.*s\n", (int)size, value);
765 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
771 req->r_inode = inode;
773 req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
775 req->r_args.setxattr.flags = cpu_to_le32(flags);
776 req->r_path2 = kstrdup(name, GFP_NOFS);
778 req->r_pages = pages;
779 req->r_num_pages = nr_pages;
780 req->r_data_len = size;
782 dout("xattr.ver (before): %lld\n", ci->i_xattrs.version);
783 parent_inode = ceph_get_dentry_parent_inode(dentry);
784 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
786 ceph_mdsc_put_request(req);
787 dout("xattr.ver (after): %lld\n", ci->i_xattrs.version);
791 for (i = 0; i < nr_pages; i++)
792 __free_page(pages[i]);
798 int ceph_setxattr(struct dentry *dentry, const char *name,
799 const void *value, size_t size, int flags)
801 struct inode *inode = dentry->d_inode;
802 struct ceph_vxattr *vxattr;
803 struct ceph_inode_info *ci = ceph_inode(inode);
807 int name_len = strlen(name);
809 char *newname = NULL;
811 struct ceph_inode_xattr *xattr = NULL;
812 int required_blob_size;
814 if (ceph_snap(inode) != CEPH_NOSNAP)
817 if (!ceph_is_valid_xattr(name))
820 vxattr = ceph_match_vxattr(inode, name);
821 if (vxattr && vxattr->readonly)
824 /* pass any unhandled ceph.* xattrs through to the MDS */
825 if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
826 goto do_sync_unlocked;
828 /* preallocate memory for xattr name, value, index node */
830 newname = kmemdup(name, name_len + 1, GFP_NOFS);
835 newval = kmemdup(value, val_len, GFP_NOFS);
840 xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
844 spin_lock(&ci->i_ceph_lock);
846 issued = __ceph_caps_issued(ci, NULL);
847 dout("setxattr %p issued %s\n", inode, ceph_cap_string(issued));
848 if (!(issued & CEPH_CAP_XATTR_EXCL))
850 __build_xattrs(inode);
852 required_blob_size = __get_required_blob_size(ci, name_len, val_len);
854 if (!ci->i_xattrs.prealloc_blob ||
855 required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
856 struct ceph_buffer *blob;
858 spin_unlock(&ci->i_ceph_lock);
859 dout(" preaallocating new blob size=%d\n", required_blob_size);
860 blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
863 spin_lock(&ci->i_ceph_lock);
864 if (ci->i_xattrs.prealloc_blob)
865 ceph_buffer_put(ci->i_xattrs.prealloc_blob);
866 ci->i_xattrs.prealloc_blob = blob;
870 err = __set_xattr(ci, newname, name_len, newval,
871 val_len, 1, 1, 1, &xattr);
873 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
874 ci->i_xattrs.dirty = true;
875 inode->i_ctime = CURRENT_TIME;
877 spin_unlock(&ci->i_ceph_lock);
879 __mark_inode_dirty(inode, dirty);
883 spin_unlock(&ci->i_ceph_lock);
885 err = ceph_sync_setxattr(dentry, name, value, size, flags);
893 static int ceph_send_removexattr(struct dentry *dentry, const char *name)
895 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
896 struct ceph_mds_client *mdsc = fsc->mdsc;
897 struct inode *inode = dentry->d_inode;
898 struct inode *parent_inode;
899 struct ceph_mds_request *req;
902 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_RMXATTR,
906 req->r_inode = inode;
908 req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
910 req->r_path2 = kstrdup(name, GFP_NOFS);
912 parent_inode = ceph_get_dentry_parent_inode(dentry);
913 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
915 ceph_mdsc_put_request(req);
919 int ceph_removexattr(struct dentry *dentry, const char *name)
921 struct inode *inode = dentry->d_inode;
922 struct ceph_vxattr *vxattr;
923 struct ceph_inode_info *ci = ceph_inode(inode);
926 int required_blob_size;
929 if (ceph_snap(inode) != CEPH_NOSNAP)
932 if (!ceph_is_valid_xattr(name))
935 vxattr = ceph_match_vxattr(inode, name);
936 if (vxattr && vxattr->readonly)
939 /* pass any unhandled ceph.* xattrs through to the MDS */
940 if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
941 goto do_sync_unlocked;
944 spin_lock(&ci->i_ceph_lock);
946 issued = __ceph_caps_issued(ci, NULL);
947 dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued));
949 if (!(issued & CEPH_CAP_XATTR_EXCL))
951 __build_xattrs(inode);
953 required_blob_size = __get_required_blob_size(ci, 0, 0);
955 if (!ci->i_xattrs.prealloc_blob ||
956 required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
957 struct ceph_buffer *blob;
959 spin_unlock(&ci->i_ceph_lock);
960 dout(" preaallocating new blob size=%d\n", required_blob_size);
961 blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
964 spin_lock(&ci->i_ceph_lock);
965 if (ci->i_xattrs.prealloc_blob)
966 ceph_buffer_put(ci->i_xattrs.prealloc_blob);
967 ci->i_xattrs.prealloc_blob = blob;
971 err = __remove_xattr_by_name(ceph_inode(inode), name);
973 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
974 ci->i_xattrs.dirty = true;
975 inode->i_ctime = CURRENT_TIME;
976 spin_unlock(&ci->i_ceph_lock);
978 __mark_inode_dirty(inode, dirty);
981 spin_unlock(&ci->i_ceph_lock);
983 err = ceph_send_removexattr(dentry, name);