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
,
37 static size_t ceph_vxattrcb_dir_entries(struct ceph_inode_info
*ci
, char *val
,
40 return snprintf(val
, size
, "%lld", ci
->i_files
+ ci
->i_subdirs
);
43 static size_t ceph_vxattrcb_dir_files(struct ceph_inode_info
*ci
, char *val
,
46 return snprintf(val
, size
, "%lld", ci
->i_files
);
49 static size_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info
*ci
, char *val
,
52 return snprintf(val
, size
, "%lld", ci
->i_subdirs
);
55 static size_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info
*ci
, char *val
,
58 return snprintf(val
, size
, "%lld", ci
->i_rfiles
+ ci
->i_rsubdirs
);
61 static size_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info
*ci
, char *val
,
64 return snprintf(val
, size
, "%lld", ci
->i_rfiles
);
67 static size_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info
*ci
, char *val
,
70 return snprintf(val
, size
, "%lld", ci
->i_rsubdirs
);
73 static size_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info
*ci
, char *val
,
76 return snprintf(val
, size
, "%lld", ci
->i_rbytes
);
79 static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info
*ci
, char *val
,
82 return snprintf(val
, size
, "%ld.09%ld", (long)ci
->i_rctime
.tv_sec
,
83 (long)ci
->i_rctime
.tv_nsec
);
86 #define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
88 #define XATTR_NAME_CEPH(_type, _name) \
90 .name = CEPH_XATTR_NAME(_type, _name), \
91 .name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
92 .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
96 static struct ceph_vxattr ceph_dir_vxattrs
[] = {
97 XATTR_NAME_CEPH(dir
, entries
),
98 XATTR_NAME_CEPH(dir
, files
),
99 XATTR_NAME_CEPH(dir
, subdirs
),
100 XATTR_NAME_CEPH(dir
, rentries
),
101 XATTR_NAME_CEPH(dir
, rfiles
),
102 XATTR_NAME_CEPH(dir
, rsubdirs
),
103 XATTR_NAME_CEPH(dir
, rbytes
),
104 XATTR_NAME_CEPH(dir
, rctime
),
105 { 0 } /* Required table terminator */
107 static size_t ceph_dir_vxattrs_name_size
; /* total size of all names */
111 static size_t ceph_vxattrcb_file_layout(struct ceph_inode_info
*ci
, char *val
,
116 ret
= snprintf(val
, size
,
117 "chunk_bytes=%lld\nstripe_count=%lld\nobject_size=%lld\n",
118 (unsigned long long)ceph_file_layout_su(ci
->i_layout
),
119 (unsigned long long)ceph_file_layout_stripe_count(ci
->i_layout
),
120 (unsigned long long)ceph_file_layout_object_size(ci
->i_layout
));
122 if (ceph_file_layout_pg_preferred(ci
->i_layout
) >= 0) {
125 ret
+= snprintf(val
, size
, "preferred_osd=%lld\n",
126 (unsigned long long)ceph_file_layout_pg_preferred(
133 static struct ceph_vxattr ceph_file_vxattrs
[] = {
134 XATTR_NAME_CEPH(file
, layout
),
135 /* The following extended attribute name is deprecated */
137 .name
= XATTR_CEPH_PREFIX
"layout",
138 .name_size
= sizeof (XATTR_CEPH_PREFIX
"layout"),
139 .getxattr_cb
= ceph_vxattrcb_file_layout
,
142 { 0 } /* Required table terminator */
144 static size_t ceph_file_vxattrs_name_size
; /* total size of all names */
146 static struct ceph_vxattr
*ceph_inode_vxattrs(struct inode
*inode
)
148 if (S_ISDIR(inode
->i_mode
))
149 return ceph_dir_vxattrs
;
150 else if (S_ISREG(inode
->i_mode
))
151 return ceph_file_vxattrs
;
155 static size_t ceph_vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
157 if (vxattrs
== ceph_dir_vxattrs
)
158 return ceph_dir_vxattrs_name_size
;
159 if (vxattrs
== ceph_file_vxattrs
)
160 return ceph_file_vxattrs_name_size
;
167 * Compute the aggregate size (including terminating '\0') of all
168 * virtual extended attribute names in the given vxattr table.
170 static size_t __init
vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
172 struct ceph_vxattr
*vxattr
;
175 for (vxattr
= vxattrs
; vxattr
->name
; vxattr
++)
176 size
+= vxattr
->name_size
;
181 /* Routines called at initialization and exit time */
183 void __init
ceph_xattr_init(void)
185 ceph_dir_vxattrs_name_size
= vxattrs_name_size(ceph_dir_vxattrs
);
186 ceph_file_vxattrs_name_size
= vxattrs_name_size(ceph_file_vxattrs
);
189 void ceph_xattr_exit(void)
191 ceph_dir_vxattrs_name_size
= 0;
192 ceph_file_vxattrs_name_size
= 0;
195 static struct ceph_vxattr
*ceph_match_vxattr(struct inode
*inode
,
198 struct ceph_vxattr
*vxattr
= ceph_inode_vxattrs(inode
);
201 while (vxattr
->name
) {
202 if (!strcmp(vxattr
->name
, name
))
211 static int __set_xattr(struct ceph_inode_info
*ci
,
212 const char *name
, int name_len
,
213 const char *val
, int val_len
,
215 int should_free_name
, int should_free_val
,
216 struct ceph_inode_xattr
**newxattr
)
219 struct rb_node
*parent
= NULL
;
220 struct ceph_inode_xattr
*xattr
= NULL
;
224 p
= &ci
->i_xattrs
.index
.rb_node
;
227 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
228 c
= strncmp(name
, xattr
->name
, min(name_len
, xattr
->name_len
));
234 if (name_len
== xattr
->name_len
)
236 else if (name_len
< xattr
->name_len
)
248 xattr
->name_len
= name_len
;
249 xattr
->should_free_name
= should_free_name
;
251 ci
->i_xattrs
.count
++;
252 dout("__set_xattr count=%d\n", ci
->i_xattrs
.count
);
256 if (xattr
->should_free_val
)
257 kfree((void *)xattr
->val
);
259 if (should_free_name
) {
263 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
264 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
266 ci
->i_xattrs
.names_size
+= name_len
;
267 ci
->i_xattrs
.vals_size
+= val_len
;
273 xattr
->val_len
= val_len
;
274 xattr
->dirty
= dirty
;
275 xattr
->should_free_val
= (val
&& should_free_val
);
278 rb_link_node(&xattr
->node
, parent
, p
);
279 rb_insert_color(&xattr
->node
, &ci
->i_xattrs
.index
);
280 dout("__set_xattr_val p=%p\n", p
);
283 dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
284 ceph_vinop(&ci
->vfs_inode
), xattr
, name
, val_len
, val
);
289 static struct ceph_inode_xattr
*__get_xattr(struct ceph_inode_info
*ci
,
293 struct rb_node
*parent
= NULL
;
294 struct ceph_inode_xattr
*xattr
= NULL
;
295 int name_len
= strlen(name
);
298 p
= &ci
->i_xattrs
.index
.rb_node
;
301 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
302 c
= strncmp(name
, xattr
->name
, xattr
->name_len
);
303 if (c
== 0 && name_len
> xattr
->name_len
)
310 dout("__get_xattr %s: found %.*s\n", name
,
311 xattr
->val_len
, xattr
->val
);
316 dout("__get_xattr %s: not found\n", name
);
321 static void __free_xattr(struct ceph_inode_xattr
*xattr
)
325 if (xattr
->should_free_name
)
326 kfree((void *)xattr
->name
);
327 if (xattr
->should_free_val
)
328 kfree((void *)xattr
->val
);
333 static int __remove_xattr(struct ceph_inode_info
*ci
,
334 struct ceph_inode_xattr
*xattr
)
339 rb_erase(&xattr
->node
, &ci
->i_xattrs
.index
);
341 if (xattr
->should_free_name
)
342 kfree((void *)xattr
->name
);
343 if (xattr
->should_free_val
)
344 kfree((void *)xattr
->val
);
346 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
347 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
348 ci
->i_xattrs
.count
--;
354 static int __remove_xattr_by_name(struct ceph_inode_info
*ci
,
358 struct ceph_inode_xattr
*xattr
;
361 p
= &ci
->i_xattrs
.index
.rb_node
;
362 xattr
= __get_xattr(ci
, name
);
363 err
= __remove_xattr(ci
, xattr
);
367 static char *__copy_xattr_names(struct ceph_inode_info
*ci
,
371 struct ceph_inode_xattr
*xattr
= NULL
;
373 p
= rb_first(&ci
->i_xattrs
.index
);
374 dout("__copy_xattr_names count=%d\n", ci
->i_xattrs
.count
);
377 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
378 memcpy(dest
, xattr
->name
, xattr
->name_len
);
379 dest
[xattr
->name_len
] = '\0';
381 dout("dest=%s %p (%s) (%d/%d)\n", dest
, xattr
, xattr
->name
,
382 xattr
->name_len
, ci
->i_xattrs
.names_size
);
384 dest
+= xattr
->name_len
+ 1;
391 void __ceph_destroy_xattrs(struct ceph_inode_info
*ci
)
393 struct rb_node
*p
, *tmp
;
394 struct ceph_inode_xattr
*xattr
= NULL
;
396 p
= rb_first(&ci
->i_xattrs
.index
);
398 dout("__ceph_destroy_xattrs p=%p\n", p
);
401 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
404 dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p
,
405 xattr
->name_len
, xattr
->name
);
406 rb_erase(tmp
, &ci
->i_xattrs
.index
);
411 ci
->i_xattrs
.names_size
= 0;
412 ci
->i_xattrs
.vals_size
= 0;
413 ci
->i_xattrs
.index_version
= 0;
414 ci
->i_xattrs
.count
= 0;
415 ci
->i_xattrs
.index
= RB_ROOT
;
418 static int __build_xattrs(struct inode
*inode
)
419 __releases(ci
->i_ceph_lock
)
420 __acquires(ci
->i_ceph_lock
)
426 const char *name
, *val
;
427 struct ceph_inode_info
*ci
= ceph_inode(inode
);
429 struct ceph_inode_xattr
**xattrs
= NULL
;
433 dout("__build_xattrs() len=%d\n",
434 ci
->i_xattrs
.blob
? (int)ci
->i_xattrs
.blob
->vec
.iov_len
: 0);
436 if (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)
437 return 0; /* already built */
439 __ceph_destroy_xattrs(ci
);
442 /* updated internal xattr rb tree */
443 if (ci
->i_xattrs
.blob
&& ci
->i_xattrs
.blob
->vec
.iov_len
> 4) {
444 p
= ci
->i_xattrs
.blob
->vec
.iov_base
;
445 end
= p
+ ci
->i_xattrs
.blob
->vec
.iov_len
;
446 ceph_decode_32_safe(&p
, end
, numattr
, bad
);
447 xattr_version
= ci
->i_xattrs
.version
;
448 spin_unlock(&ci
->i_ceph_lock
);
450 xattrs
= kcalloc(numattr
, sizeof(struct ceph_xattr
*),
455 memset(xattrs
, 0, numattr
*sizeof(struct ceph_xattr
*));
456 for (i
= 0; i
< numattr
; i
++) {
457 xattrs
[i
] = kmalloc(sizeof(struct ceph_inode_xattr
),
463 spin_lock(&ci
->i_ceph_lock
);
464 if (ci
->i_xattrs
.version
!= xattr_version
) {
465 /* lost a race, retry */
466 for (i
= 0; i
< numattr
; i
++)
473 ceph_decode_32_safe(&p
, end
, len
, bad
);
477 ceph_decode_32_safe(&p
, end
, len
, bad
);
481 err
= __set_xattr(ci
, name
, namelen
, val
, len
,
482 0, 0, 0, &xattrs
[numattr
]);
489 ci
->i_xattrs
.index_version
= ci
->i_xattrs
.version
;
490 ci
->i_xattrs
.dirty
= false;
494 spin_lock(&ci
->i_ceph_lock
);
497 for (i
= 0; i
< numattr
; i
++)
501 ci
->i_xattrs
.names_size
= 0;
505 static int __get_required_blob_size(struct ceph_inode_info
*ci
, int name_size
,
509 * 4 bytes for the length, and additional 4 bytes per each xattr name,
510 * 4 bytes per each value
512 int size
= 4 + ci
->i_xattrs
.count
*(4 + 4) +
513 ci
->i_xattrs
.names_size
+
514 ci
->i_xattrs
.vals_size
;
515 dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
516 ci
->i_xattrs
.count
, ci
->i_xattrs
.names_size
,
517 ci
->i_xattrs
.vals_size
);
520 size
+= 4 + 4 + name_size
+ val_size
;
526 * If there are dirty xattrs, reencode xattrs into the prealloc_blob
527 * and swap into place.
529 void __ceph_build_xattrs_blob(struct ceph_inode_info
*ci
)
532 struct ceph_inode_xattr
*xattr
= NULL
;
535 dout("__build_xattrs_blob %p\n", &ci
->vfs_inode
);
536 if (ci
->i_xattrs
.dirty
) {
537 int need
= __get_required_blob_size(ci
, 0, 0);
539 BUG_ON(need
> ci
->i_xattrs
.prealloc_blob
->alloc_len
);
541 p
= rb_first(&ci
->i_xattrs
.index
);
542 dest
= ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
544 ceph_encode_32(&dest
, ci
->i_xattrs
.count
);
546 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
548 ceph_encode_32(&dest
, xattr
->name_len
);
549 memcpy(dest
, xattr
->name
, xattr
->name_len
);
550 dest
+= xattr
->name_len
;
551 ceph_encode_32(&dest
, xattr
->val_len
);
552 memcpy(dest
, xattr
->val
, xattr
->val_len
);
553 dest
+= xattr
->val_len
;
558 /* adjust buffer len; it may be larger than we need */
559 ci
->i_xattrs
.prealloc_blob
->vec
.iov_len
=
560 dest
- ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
562 if (ci
->i_xattrs
.blob
)
563 ceph_buffer_put(ci
->i_xattrs
.blob
);
564 ci
->i_xattrs
.blob
= ci
->i_xattrs
.prealloc_blob
;
565 ci
->i_xattrs
.prealloc_blob
= NULL
;
566 ci
->i_xattrs
.dirty
= false;
567 ci
->i_xattrs
.version
++;
571 ssize_t
ceph_getxattr(struct dentry
*dentry
, const char *name
, void *value
,
574 struct inode
*inode
= dentry
->d_inode
;
575 struct ceph_inode_info
*ci
= ceph_inode(inode
);
577 struct ceph_inode_xattr
*xattr
;
578 struct ceph_vxattr
*vxattr
= NULL
;
580 if (!ceph_is_valid_xattr(name
))
583 /* let's see if a virtual xattr was requested */
584 vxattr
= ceph_match_vxattr(inode
, name
);
586 spin_lock(&ci
->i_ceph_lock
);
587 dout("getxattr %p ver=%lld index_ver=%lld\n", inode
,
588 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
590 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
591 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
594 spin_unlock(&ci
->i_ceph_lock
);
595 /* get xattrs from mds (if we don't already have them) */
596 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
601 spin_lock(&ci
->i_ceph_lock
);
603 if (vxattr
&& vxattr
->readonly
) {
604 err
= vxattr
->getxattr_cb(ci
, value
, size
);
608 err
= __build_xattrs(inode
);
613 err
= -ENODATA
; /* == ENOATTR */
614 xattr
= __get_xattr(ci
, name
);
617 err
= vxattr
->getxattr_cb(ci
, value
, size
);
622 if (size
&& size
< xattr
->val_len
)
625 err
= xattr
->val_len
;
629 memcpy(value
, xattr
->val
, xattr
->val_len
);
632 spin_unlock(&ci
->i_ceph_lock
);
636 ssize_t
ceph_listxattr(struct dentry
*dentry
, char *names
, size_t size
)
638 struct inode
*inode
= dentry
->d_inode
;
639 struct ceph_inode_info
*ci
= ceph_inode(inode
);
640 struct ceph_vxattr
*vxattrs
= ceph_inode_vxattrs(inode
);
647 spin_lock(&ci
->i_ceph_lock
);
648 dout("listxattr %p ver=%lld index_ver=%lld\n", inode
,
649 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
651 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
652 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
655 spin_unlock(&ci
->i_ceph_lock
);
656 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
661 spin_lock(&ci
->i_ceph_lock
);
663 err
= __build_xattrs(inode
);
669 * Start with virtual dir xattr names (if any) (including
670 * terminating '\0' characters for each).
672 vir_namelen
= ceph_vxattrs_name_size(vxattrs
);
674 /* adding 1 byte per each variable due to the null termination */
675 namelen
= vir_namelen
+ ci
->i_xattrs
.names_size
+ ci
->i_xattrs
.count
;
677 if (size
&& namelen
> size
)
684 names
= __copy_xattr_names(ci
, names
);
686 /* virtual xattr names, too */
688 for (i
= 0; vxattrs
[i
].name
; i
++) {
689 len
= sprintf(names
, "%s", vxattrs
[i
].name
);
694 spin_unlock(&ci
->i_ceph_lock
);
698 static int ceph_sync_setxattr(struct dentry
*dentry
, const char *name
,
699 const char *value
, size_t size
, int flags
)
701 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
702 struct inode
*inode
= dentry
->d_inode
;
703 struct ceph_inode_info
*ci
= ceph_inode(inode
);
704 struct inode
*parent_inode
;
705 struct ceph_mds_request
*req
;
706 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
709 struct page
**pages
= NULL
;
712 /* copy value into some pages */
713 nr_pages
= calc_pages_for(0, size
);
715 pages
= kmalloc(sizeof(pages
[0])*nr_pages
, GFP_NOFS
);
719 for (i
= 0; i
< nr_pages
; i
++) {
720 pages
[i
] = __page_cache_alloc(GFP_NOFS
);
725 kaddr
= kmap(pages
[i
]);
726 memcpy(kaddr
, value
+ i
*PAGE_CACHE_SIZE
,
727 min(PAGE_CACHE_SIZE
, size
-i
*PAGE_CACHE_SIZE
));
731 dout("setxattr value=%.*s\n", (int)size
, value
);
734 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_SETXATTR
,
740 req
->r_inode
= inode
;
742 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
744 req
->r_args
.setxattr
.flags
= cpu_to_le32(flags
);
745 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
747 req
->r_pages
= pages
;
748 req
->r_num_pages
= nr_pages
;
749 req
->r_data_len
= size
;
751 dout("xattr.ver (before): %lld\n", ci
->i_xattrs
.version
);
752 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
753 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
755 ceph_mdsc_put_request(req
);
756 dout("xattr.ver (after): %lld\n", ci
->i_xattrs
.version
);
760 for (i
= 0; i
< nr_pages
; i
++)
761 __free_page(pages
[i
]);
767 int ceph_setxattr(struct dentry
*dentry
, const char *name
,
768 const void *value
, size_t size
, int flags
)
770 struct inode
*inode
= dentry
->d_inode
;
771 struct ceph_vxattr
*vxattr
;
772 struct ceph_inode_info
*ci
= ceph_inode(inode
);
776 int name_len
= strlen(name
);
778 char *newname
= NULL
;
780 struct ceph_inode_xattr
*xattr
= NULL
;
781 int required_blob_size
;
783 if (ceph_snap(inode
) != CEPH_NOSNAP
)
786 if (!ceph_is_valid_xattr(name
))
789 vxattr
= ceph_match_vxattr(inode
, name
);
790 if (vxattr
&& vxattr
->readonly
)
793 /* preallocate memory for xattr name, value, index node */
795 newname
= kmemdup(name
, name_len
+ 1, GFP_NOFS
);
800 newval
= kmemdup(value
, val_len
, GFP_NOFS
);
805 xattr
= kmalloc(sizeof(struct ceph_inode_xattr
), GFP_NOFS
);
809 spin_lock(&ci
->i_ceph_lock
);
811 issued
= __ceph_caps_issued(ci
, NULL
);
812 dout("setxattr %p issued %s\n", inode
, ceph_cap_string(issued
));
813 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
815 __build_xattrs(inode
);
817 required_blob_size
= __get_required_blob_size(ci
, name_len
, val_len
);
819 if (!ci
->i_xattrs
.prealloc_blob
||
820 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
821 struct ceph_buffer
*blob
;
823 spin_unlock(&ci
->i_ceph_lock
);
824 dout(" preaallocating new blob size=%d\n", required_blob_size
);
825 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
828 spin_lock(&ci
->i_ceph_lock
);
829 if (ci
->i_xattrs
.prealloc_blob
)
830 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
831 ci
->i_xattrs
.prealloc_blob
= blob
;
835 err
= __set_xattr(ci
, newname
, name_len
, newval
,
836 val_len
, 1, 1, 1, &xattr
);
838 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
839 ci
->i_xattrs
.dirty
= true;
840 inode
->i_ctime
= CURRENT_TIME
;
842 spin_unlock(&ci
->i_ceph_lock
);
844 __mark_inode_dirty(inode
, dirty
);
848 spin_unlock(&ci
->i_ceph_lock
);
849 err
= ceph_sync_setxattr(dentry
, name
, value
, size
, flags
);
857 static int ceph_send_removexattr(struct dentry
*dentry
, const char *name
)
859 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
860 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
861 struct inode
*inode
= dentry
->d_inode
;
862 struct inode
*parent_inode
;
863 struct ceph_mds_request
*req
;
866 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_RMXATTR
,
870 req
->r_inode
= inode
;
872 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
874 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
876 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
877 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
879 ceph_mdsc_put_request(req
);
883 int ceph_removexattr(struct dentry
*dentry
, const char *name
)
885 struct inode
*inode
= dentry
->d_inode
;
886 struct ceph_vxattr
*vxattr
;
887 struct ceph_inode_info
*ci
= ceph_inode(inode
);
890 int required_blob_size
;
893 if (ceph_snap(inode
) != CEPH_NOSNAP
)
896 if (!ceph_is_valid_xattr(name
))
899 vxattr
= ceph_match_vxattr(inode
, name
);
900 if (vxattr
&& vxattr
->readonly
)
904 spin_lock(&ci
->i_ceph_lock
);
906 issued
= __ceph_caps_issued(ci
, NULL
);
907 dout("removexattr %p issued %s\n", inode
, ceph_cap_string(issued
));
909 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
911 __build_xattrs(inode
);
913 required_blob_size
= __get_required_blob_size(ci
, 0, 0);
915 if (!ci
->i_xattrs
.prealloc_blob
||
916 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
917 struct ceph_buffer
*blob
;
919 spin_unlock(&ci
->i_ceph_lock
);
920 dout(" preaallocating new blob size=%d\n", required_blob_size
);
921 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
924 spin_lock(&ci
->i_ceph_lock
);
925 if (ci
->i_xattrs
.prealloc_blob
)
926 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
927 ci
->i_xattrs
.prealloc_blob
= blob
;
931 err
= __remove_xattr_by_name(ceph_inode(inode
), name
);
933 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
934 ci
->i_xattrs
.dirty
= true;
935 inode
->i_ctime
= CURRENT_TIME
;
936 spin_unlock(&ci
->i_ceph_lock
);
938 __mark_inode_dirty(inode
, dirty
);
941 spin_unlock(&ci
->i_ceph_lock
);
942 err
= ceph_send_removexattr(dentry
, name
);