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 size_t ceph_vxattrcb_dir_entries(struct ceph_inode_info
*ci
, char *val
,
41 return snprintf(val
, size
, "%lld", ci
->i_files
+ ci
->i_subdirs
);
44 static size_t ceph_vxattrcb_dir_files(struct ceph_inode_info
*ci
, char *val
,
47 return snprintf(val
, size
, "%lld", ci
->i_files
);
50 static size_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info
*ci
, char *val
,
53 return snprintf(val
, size
, "%lld", ci
->i_subdirs
);
56 static size_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info
*ci
, char *val
,
59 return snprintf(val
, size
, "%lld", ci
->i_rfiles
+ ci
->i_rsubdirs
);
62 static size_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info
*ci
, char *val
,
65 return snprintf(val
, size
, "%lld", ci
->i_rfiles
);
68 static size_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info
*ci
, char *val
,
71 return snprintf(val
, size
, "%lld", ci
->i_rsubdirs
);
74 static size_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info
*ci
, char *val
,
77 return snprintf(val
, size
, "%lld", ci
->i_rbytes
);
80 static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info
*ci
, char *val
,
83 return snprintf(val
, size
, "%ld.09%ld", (long)ci
->i_rctime
.tv_sec
,
84 (long)ci
->i_rctime
.tv_nsec
);
87 #define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
89 #define XATTR_NAME_CEPH(_type, _name) \
91 .name = CEPH_XATTR_NAME(_type, _name), \
92 .name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
93 .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
99 static struct ceph_vxattr ceph_dir_vxattrs
[] = {
100 XATTR_NAME_CEPH(dir
, entries
),
101 XATTR_NAME_CEPH(dir
, files
),
102 XATTR_NAME_CEPH(dir
, subdirs
),
103 XATTR_NAME_CEPH(dir
, rentries
),
104 XATTR_NAME_CEPH(dir
, rfiles
),
105 XATTR_NAME_CEPH(dir
, rsubdirs
),
106 XATTR_NAME_CEPH(dir
, rbytes
),
107 XATTR_NAME_CEPH(dir
, rctime
),
108 { 0 } /* Required table terminator */
110 static size_t ceph_dir_vxattrs_name_size
; /* total size of all names */
114 static size_t ceph_vxattrcb_file_layout(struct ceph_inode_info
*ci
, char *val
,
119 ret
= snprintf(val
, size
,
120 "chunk_bytes=%lld\nstripe_count=%lld\nobject_size=%lld\n",
121 (unsigned long long)ceph_file_layout_su(ci
->i_layout
),
122 (unsigned long long)ceph_file_layout_stripe_count(ci
->i_layout
),
123 (unsigned long long)ceph_file_layout_object_size(ci
->i_layout
));
127 static struct ceph_vxattr ceph_file_vxattrs
[] = {
128 XATTR_NAME_CEPH(file
, layout
),
129 { 0 } /* Required table terminator */
131 static size_t ceph_file_vxattrs_name_size
; /* total size of all names */
133 static struct ceph_vxattr
*ceph_inode_vxattrs(struct inode
*inode
)
135 if (S_ISDIR(inode
->i_mode
))
136 return ceph_dir_vxattrs
;
137 else if (S_ISREG(inode
->i_mode
))
138 return ceph_file_vxattrs
;
142 static size_t ceph_vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
144 if (vxattrs
== ceph_dir_vxattrs
)
145 return ceph_dir_vxattrs_name_size
;
146 if (vxattrs
== ceph_file_vxattrs
)
147 return ceph_file_vxattrs_name_size
;
154 * Compute the aggregate size (including terminating '\0') of all
155 * virtual extended attribute names in the given vxattr table.
157 static size_t __init
vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
159 struct ceph_vxattr
*vxattr
;
162 for (vxattr
= vxattrs
; vxattr
->name
; vxattr
++)
164 size
+= vxattr
->name_size
;
169 /* Routines called at initialization and exit time */
171 void __init
ceph_xattr_init(void)
173 ceph_dir_vxattrs_name_size
= vxattrs_name_size(ceph_dir_vxattrs
);
174 ceph_file_vxattrs_name_size
= vxattrs_name_size(ceph_file_vxattrs
);
177 void ceph_xattr_exit(void)
179 ceph_dir_vxattrs_name_size
= 0;
180 ceph_file_vxattrs_name_size
= 0;
183 static struct ceph_vxattr
*ceph_match_vxattr(struct inode
*inode
,
186 struct ceph_vxattr
*vxattr
= ceph_inode_vxattrs(inode
);
189 while (vxattr
->name
) {
190 if (!strcmp(vxattr
->name
, name
))
199 static int __set_xattr(struct ceph_inode_info
*ci
,
200 const char *name
, int name_len
,
201 const char *val
, int val_len
,
203 int should_free_name
, int should_free_val
,
204 struct ceph_inode_xattr
**newxattr
)
207 struct rb_node
*parent
= NULL
;
208 struct ceph_inode_xattr
*xattr
= NULL
;
212 p
= &ci
->i_xattrs
.index
.rb_node
;
215 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
216 c
= strncmp(name
, xattr
->name
, min(name_len
, xattr
->name_len
));
222 if (name_len
== xattr
->name_len
)
224 else if (name_len
< xattr
->name_len
)
236 xattr
->name_len
= name_len
;
237 xattr
->should_free_name
= should_free_name
;
239 ci
->i_xattrs
.count
++;
240 dout("__set_xattr count=%d\n", ci
->i_xattrs
.count
);
244 if (xattr
->should_free_val
)
245 kfree((void *)xattr
->val
);
247 if (should_free_name
) {
251 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
252 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
254 ci
->i_xattrs
.names_size
+= name_len
;
255 ci
->i_xattrs
.vals_size
+= val_len
;
261 xattr
->val_len
= val_len
;
262 xattr
->dirty
= dirty
;
263 xattr
->should_free_val
= (val
&& should_free_val
);
266 rb_link_node(&xattr
->node
, parent
, p
);
267 rb_insert_color(&xattr
->node
, &ci
->i_xattrs
.index
);
268 dout("__set_xattr_val p=%p\n", p
);
271 dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
272 ceph_vinop(&ci
->vfs_inode
), xattr
, name
, val_len
, val
);
277 static struct ceph_inode_xattr
*__get_xattr(struct ceph_inode_info
*ci
,
281 struct rb_node
*parent
= NULL
;
282 struct ceph_inode_xattr
*xattr
= NULL
;
283 int name_len
= strlen(name
);
286 p
= &ci
->i_xattrs
.index
.rb_node
;
289 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
290 c
= strncmp(name
, xattr
->name
, xattr
->name_len
);
291 if (c
== 0 && name_len
> xattr
->name_len
)
298 dout("__get_xattr %s: found %.*s\n", name
,
299 xattr
->val_len
, xattr
->val
);
304 dout("__get_xattr %s: not found\n", name
);
309 static void __free_xattr(struct ceph_inode_xattr
*xattr
)
313 if (xattr
->should_free_name
)
314 kfree((void *)xattr
->name
);
315 if (xattr
->should_free_val
)
316 kfree((void *)xattr
->val
);
321 static int __remove_xattr(struct ceph_inode_info
*ci
,
322 struct ceph_inode_xattr
*xattr
)
327 rb_erase(&xattr
->node
, &ci
->i_xattrs
.index
);
329 if (xattr
->should_free_name
)
330 kfree((void *)xattr
->name
);
331 if (xattr
->should_free_val
)
332 kfree((void *)xattr
->val
);
334 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
335 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
336 ci
->i_xattrs
.count
--;
342 static int __remove_xattr_by_name(struct ceph_inode_info
*ci
,
346 struct ceph_inode_xattr
*xattr
;
349 p
= &ci
->i_xattrs
.index
.rb_node
;
350 xattr
= __get_xattr(ci
, name
);
351 err
= __remove_xattr(ci
, xattr
);
355 static char *__copy_xattr_names(struct ceph_inode_info
*ci
,
359 struct ceph_inode_xattr
*xattr
= NULL
;
361 p
= rb_first(&ci
->i_xattrs
.index
);
362 dout("__copy_xattr_names count=%d\n", ci
->i_xattrs
.count
);
365 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
366 memcpy(dest
, xattr
->name
, xattr
->name_len
);
367 dest
[xattr
->name_len
] = '\0';
369 dout("dest=%s %p (%s) (%d/%d)\n", dest
, xattr
, xattr
->name
,
370 xattr
->name_len
, ci
->i_xattrs
.names_size
);
372 dest
+= xattr
->name_len
+ 1;
379 void __ceph_destroy_xattrs(struct ceph_inode_info
*ci
)
381 struct rb_node
*p
, *tmp
;
382 struct ceph_inode_xattr
*xattr
= NULL
;
384 p
= rb_first(&ci
->i_xattrs
.index
);
386 dout("__ceph_destroy_xattrs p=%p\n", p
);
389 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
392 dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p
,
393 xattr
->name_len
, xattr
->name
);
394 rb_erase(tmp
, &ci
->i_xattrs
.index
);
399 ci
->i_xattrs
.names_size
= 0;
400 ci
->i_xattrs
.vals_size
= 0;
401 ci
->i_xattrs
.index_version
= 0;
402 ci
->i_xattrs
.count
= 0;
403 ci
->i_xattrs
.index
= RB_ROOT
;
406 static int __build_xattrs(struct inode
*inode
)
407 __releases(ci
->i_ceph_lock
)
408 __acquires(ci
->i_ceph_lock
)
414 const char *name
, *val
;
415 struct ceph_inode_info
*ci
= ceph_inode(inode
);
417 struct ceph_inode_xattr
**xattrs
= NULL
;
421 dout("__build_xattrs() len=%d\n",
422 ci
->i_xattrs
.blob
? (int)ci
->i_xattrs
.blob
->vec
.iov_len
: 0);
424 if (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)
425 return 0; /* already built */
427 __ceph_destroy_xattrs(ci
);
430 /* updated internal xattr rb tree */
431 if (ci
->i_xattrs
.blob
&& ci
->i_xattrs
.blob
->vec
.iov_len
> 4) {
432 p
= ci
->i_xattrs
.blob
->vec
.iov_base
;
433 end
= p
+ ci
->i_xattrs
.blob
->vec
.iov_len
;
434 ceph_decode_32_safe(&p
, end
, numattr
, bad
);
435 xattr_version
= ci
->i_xattrs
.version
;
436 spin_unlock(&ci
->i_ceph_lock
);
438 xattrs
= kcalloc(numattr
, sizeof(struct ceph_xattr
*),
443 memset(xattrs
, 0, numattr
*sizeof(struct ceph_xattr
*));
444 for (i
= 0; i
< numattr
; i
++) {
445 xattrs
[i
] = kmalloc(sizeof(struct ceph_inode_xattr
),
451 spin_lock(&ci
->i_ceph_lock
);
452 if (ci
->i_xattrs
.version
!= xattr_version
) {
453 /* lost a race, retry */
454 for (i
= 0; i
< numattr
; i
++)
462 ceph_decode_32_safe(&p
, end
, len
, bad
);
466 ceph_decode_32_safe(&p
, end
, len
, bad
);
470 err
= __set_xattr(ci
, name
, namelen
, val
, len
,
471 0, 0, 0, &xattrs
[numattr
]);
478 ci
->i_xattrs
.index_version
= ci
->i_xattrs
.version
;
479 ci
->i_xattrs
.dirty
= false;
483 spin_lock(&ci
->i_ceph_lock
);
486 for (i
= 0; i
< numattr
; i
++)
490 ci
->i_xattrs
.names_size
= 0;
494 static int __get_required_blob_size(struct ceph_inode_info
*ci
, int name_size
,
498 * 4 bytes for the length, and additional 4 bytes per each xattr name,
499 * 4 bytes per each value
501 int size
= 4 + ci
->i_xattrs
.count
*(4 + 4) +
502 ci
->i_xattrs
.names_size
+
503 ci
->i_xattrs
.vals_size
;
504 dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
505 ci
->i_xattrs
.count
, ci
->i_xattrs
.names_size
,
506 ci
->i_xattrs
.vals_size
);
509 size
+= 4 + 4 + name_size
+ val_size
;
515 * If there are dirty xattrs, reencode xattrs into the prealloc_blob
516 * and swap into place.
518 void __ceph_build_xattrs_blob(struct ceph_inode_info
*ci
)
521 struct ceph_inode_xattr
*xattr
= NULL
;
524 dout("__build_xattrs_blob %p\n", &ci
->vfs_inode
);
525 if (ci
->i_xattrs
.dirty
) {
526 int need
= __get_required_blob_size(ci
, 0, 0);
528 BUG_ON(need
> ci
->i_xattrs
.prealloc_blob
->alloc_len
);
530 p
= rb_first(&ci
->i_xattrs
.index
);
531 dest
= ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
533 ceph_encode_32(&dest
, ci
->i_xattrs
.count
);
535 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
537 ceph_encode_32(&dest
, xattr
->name_len
);
538 memcpy(dest
, xattr
->name
, xattr
->name_len
);
539 dest
+= xattr
->name_len
;
540 ceph_encode_32(&dest
, xattr
->val_len
);
541 memcpy(dest
, xattr
->val
, xattr
->val_len
);
542 dest
+= xattr
->val_len
;
547 /* adjust buffer len; it may be larger than we need */
548 ci
->i_xattrs
.prealloc_blob
->vec
.iov_len
=
549 dest
- ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
551 if (ci
->i_xattrs
.blob
)
552 ceph_buffer_put(ci
->i_xattrs
.blob
);
553 ci
->i_xattrs
.blob
= ci
->i_xattrs
.prealloc_blob
;
554 ci
->i_xattrs
.prealloc_blob
= NULL
;
555 ci
->i_xattrs
.dirty
= false;
556 ci
->i_xattrs
.version
++;
560 ssize_t
ceph_getxattr(struct dentry
*dentry
, const char *name
, void *value
,
563 struct inode
*inode
= dentry
->d_inode
;
564 struct ceph_inode_info
*ci
= ceph_inode(inode
);
566 struct ceph_inode_xattr
*xattr
;
567 struct ceph_vxattr
*vxattr
= NULL
;
569 if (!ceph_is_valid_xattr(name
))
572 /* let's see if a virtual xattr was requested */
573 vxattr
= ceph_match_vxattr(inode
, name
);
575 spin_lock(&ci
->i_ceph_lock
);
576 dout("getxattr %p ver=%lld index_ver=%lld\n", inode
,
577 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
579 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
580 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
583 spin_unlock(&ci
->i_ceph_lock
);
584 /* get xattrs from mds (if we don't already have them) */
585 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
590 spin_lock(&ci
->i_ceph_lock
);
592 if (vxattr
&& vxattr
->readonly
) {
593 err
= vxattr
->getxattr_cb(ci
, value
, size
);
597 err
= __build_xattrs(inode
);
602 err
= -ENODATA
; /* == ENOATTR */
603 xattr
= __get_xattr(ci
, name
);
606 err
= vxattr
->getxattr_cb(ci
, value
, size
);
611 if (size
&& size
< xattr
->val_len
)
614 err
= xattr
->val_len
;
618 memcpy(value
, xattr
->val
, xattr
->val_len
);
621 spin_unlock(&ci
->i_ceph_lock
);
625 ssize_t
ceph_listxattr(struct dentry
*dentry
, char *names
, size_t size
)
627 struct inode
*inode
= dentry
->d_inode
;
628 struct ceph_inode_info
*ci
= ceph_inode(inode
);
629 struct ceph_vxattr
*vxattrs
= ceph_inode_vxattrs(inode
);
636 spin_lock(&ci
->i_ceph_lock
);
637 dout("listxattr %p ver=%lld index_ver=%lld\n", inode
,
638 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
640 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
641 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
644 spin_unlock(&ci
->i_ceph_lock
);
645 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
650 spin_lock(&ci
->i_ceph_lock
);
652 err
= __build_xattrs(inode
);
658 * Start with virtual dir xattr names (if any) (including
659 * terminating '\0' characters for each).
661 vir_namelen
= ceph_vxattrs_name_size(vxattrs
);
663 /* adding 1 byte per each variable due to the null termination */
664 namelen
= vir_namelen
+ ci
->i_xattrs
.names_size
+ ci
->i_xattrs
.count
;
666 if (size
&& namelen
> size
)
673 names
= __copy_xattr_names(ci
, names
);
675 /* virtual xattr names, too */
677 for (i
= 0; vxattrs
[i
].name
; i
++) {
678 len
= sprintf(names
, "%s", vxattrs
[i
].name
);
683 spin_unlock(&ci
->i_ceph_lock
);
687 static int ceph_sync_setxattr(struct dentry
*dentry
, const char *name
,
688 const char *value
, size_t size
, int flags
)
690 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
691 struct inode
*inode
= dentry
->d_inode
;
692 struct ceph_inode_info
*ci
= ceph_inode(inode
);
693 struct inode
*parent_inode
;
694 struct ceph_mds_request
*req
;
695 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
698 struct page
**pages
= NULL
;
701 /* copy value into some pages */
702 nr_pages
= calc_pages_for(0, size
);
704 pages
= kmalloc(sizeof(pages
[0])*nr_pages
, GFP_NOFS
);
708 for (i
= 0; i
< nr_pages
; i
++) {
709 pages
[i
] = __page_cache_alloc(GFP_NOFS
);
714 kaddr
= kmap(pages
[i
]);
715 memcpy(kaddr
, value
+ i
*PAGE_CACHE_SIZE
,
716 min(PAGE_CACHE_SIZE
, size
-i
*PAGE_CACHE_SIZE
));
720 dout("setxattr value=%.*s\n", (int)size
, value
);
723 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_SETXATTR
,
729 req
->r_inode
= inode
;
731 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
733 req
->r_args
.setxattr
.flags
= cpu_to_le32(flags
);
734 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
736 req
->r_pages
= pages
;
737 req
->r_num_pages
= nr_pages
;
738 req
->r_data_len
= size
;
740 dout("xattr.ver (before): %lld\n", ci
->i_xattrs
.version
);
741 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
742 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
744 ceph_mdsc_put_request(req
);
745 dout("xattr.ver (after): %lld\n", ci
->i_xattrs
.version
);
749 for (i
= 0; i
< nr_pages
; i
++)
750 __free_page(pages
[i
]);
756 int ceph_setxattr(struct dentry
*dentry
, const char *name
,
757 const void *value
, size_t size
, int flags
)
759 struct inode
*inode
= dentry
->d_inode
;
760 struct ceph_vxattr
*vxattr
;
761 struct ceph_inode_info
*ci
= ceph_inode(inode
);
765 int name_len
= strlen(name
);
767 char *newname
= NULL
;
769 struct ceph_inode_xattr
*xattr
= NULL
;
770 int required_blob_size
;
772 if (ceph_snap(inode
) != CEPH_NOSNAP
)
775 if (!ceph_is_valid_xattr(name
))
778 vxattr
= ceph_match_vxattr(inode
, name
);
779 if (vxattr
&& vxattr
->readonly
)
782 /* pass any unhandled ceph.* xattrs through to the MDS */
783 if (!strncmp(name
, XATTR_CEPH_PREFIX
, XATTR_CEPH_PREFIX_LEN
))
784 goto do_sync_unlocked
;
786 /* preallocate memory for xattr name, value, index node */
788 newname
= kmemdup(name
, name_len
+ 1, GFP_NOFS
);
793 newval
= kmemdup(value
, val_len
, GFP_NOFS
);
798 xattr
= kmalloc(sizeof(struct ceph_inode_xattr
), GFP_NOFS
);
802 spin_lock(&ci
->i_ceph_lock
);
804 issued
= __ceph_caps_issued(ci
, NULL
);
805 dout("setxattr %p issued %s\n", inode
, ceph_cap_string(issued
));
806 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
808 __build_xattrs(inode
);
810 required_blob_size
= __get_required_blob_size(ci
, name_len
, val_len
);
812 if (!ci
->i_xattrs
.prealloc_blob
||
813 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
814 struct ceph_buffer
*blob
;
816 spin_unlock(&ci
->i_ceph_lock
);
817 dout(" preaallocating new blob size=%d\n", required_blob_size
);
818 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
821 spin_lock(&ci
->i_ceph_lock
);
822 if (ci
->i_xattrs
.prealloc_blob
)
823 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
824 ci
->i_xattrs
.prealloc_blob
= blob
;
828 err
= __set_xattr(ci
, newname
, name_len
, newval
,
829 val_len
, 1, 1, 1, &xattr
);
831 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
832 ci
->i_xattrs
.dirty
= true;
833 inode
->i_ctime
= CURRENT_TIME
;
835 spin_unlock(&ci
->i_ceph_lock
);
837 __mark_inode_dirty(inode
, dirty
);
841 spin_unlock(&ci
->i_ceph_lock
);
843 err
= ceph_sync_setxattr(dentry
, name
, value
, size
, flags
);
851 static int ceph_send_removexattr(struct dentry
*dentry
, const char *name
)
853 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
854 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
855 struct inode
*inode
= dentry
->d_inode
;
856 struct inode
*parent_inode
;
857 struct ceph_mds_request
*req
;
860 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_RMXATTR
,
864 req
->r_inode
= inode
;
866 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
868 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
870 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
871 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
873 ceph_mdsc_put_request(req
);
877 int ceph_removexattr(struct dentry
*dentry
, const char *name
)
879 struct inode
*inode
= dentry
->d_inode
;
880 struct ceph_vxattr
*vxattr
;
881 struct ceph_inode_info
*ci
= ceph_inode(inode
);
884 int required_blob_size
;
887 if (ceph_snap(inode
) != CEPH_NOSNAP
)
890 if (!ceph_is_valid_xattr(name
))
893 vxattr
= ceph_match_vxattr(inode
, name
);
894 if (vxattr
&& vxattr
->readonly
)
897 /* pass any unhandled ceph.* xattrs through to the MDS */
898 if (!strncmp(name
, XATTR_CEPH_PREFIX
, XATTR_CEPH_PREFIX_LEN
))
899 goto do_sync_unlocked
;
902 spin_lock(&ci
->i_ceph_lock
);
904 issued
= __ceph_caps_issued(ci
, NULL
);
905 dout("removexattr %p issued %s\n", inode
, ceph_cap_string(issued
));
907 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
909 __build_xattrs(inode
);
911 required_blob_size
= __get_required_blob_size(ci
, 0, 0);
913 if (!ci
->i_xattrs
.prealloc_blob
||
914 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
915 struct ceph_buffer
*blob
;
917 spin_unlock(&ci
->i_ceph_lock
);
918 dout(" preaallocating new blob size=%d\n", required_blob_size
);
919 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
922 spin_lock(&ci
->i_ceph_lock
);
923 if (ci
->i_xattrs
.prealloc_blob
)
924 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
925 ci
->i_xattrs
.prealloc_blob
= blob
;
929 err
= __remove_xattr_by_name(ceph_inode(inode
), name
);
931 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
932 ci
->i_xattrs
.dirty
= true;
933 inode
->i_ctime
= CURRENT_TIME
;
934 spin_unlock(&ci
->i_ceph_lock
);
936 __mark_inode_dirty(inode
, dirty
);
939 spin_unlock(&ci
->i_ceph_lock
);
941 err
= ceph_send_removexattr(dentry
, name
);