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
));
124 static struct ceph_vxattr ceph_file_vxattrs
[] = {
125 XATTR_NAME_CEPH(file
, layout
),
126 /* The following extended attribute name is deprecated */
128 .name
= XATTR_CEPH_PREFIX
"layout",
129 .name_size
= sizeof (XATTR_CEPH_PREFIX
"layout"),
130 .getxattr_cb
= ceph_vxattrcb_file_layout
,
133 { 0 } /* Required table terminator */
135 static size_t ceph_file_vxattrs_name_size
; /* total size of all names */
137 static struct ceph_vxattr
*ceph_inode_vxattrs(struct inode
*inode
)
139 if (S_ISDIR(inode
->i_mode
))
140 return ceph_dir_vxattrs
;
141 else if (S_ISREG(inode
->i_mode
))
142 return ceph_file_vxattrs
;
146 static size_t ceph_vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
148 if (vxattrs
== ceph_dir_vxattrs
)
149 return ceph_dir_vxattrs_name_size
;
150 if (vxattrs
== ceph_file_vxattrs
)
151 return ceph_file_vxattrs_name_size
;
158 * Compute the aggregate size (including terminating '\0') of all
159 * virtual extended attribute names in the given vxattr table.
161 static size_t __init
vxattrs_name_size(struct ceph_vxattr
*vxattrs
)
163 struct ceph_vxattr
*vxattr
;
166 for (vxattr
= vxattrs
; vxattr
->name
; vxattr
++)
167 size
+= vxattr
->name_size
;
172 /* Routines called at initialization and exit time */
174 void __init
ceph_xattr_init(void)
176 ceph_dir_vxattrs_name_size
= vxattrs_name_size(ceph_dir_vxattrs
);
177 ceph_file_vxattrs_name_size
= vxattrs_name_size(ceph_file_vxattrs
);
180 void ceph_xattr_exit(void)
182 ceph_dir_vxattrs_name_size
= 0;
183 ceph_file_vxattrs_name_size
= 0;
186 static struct ceph_vxattr
*ceph_match_vxattr(struct inode
*inode
,
189 struct ceph_vxattr
*vxattr
= ceph_inode_vxattrs(inode
);
192 while (vxattr
->name
) {
193 if (!strcmp(vxattr
->name
, name
))
202 static int __set_xattr(struct ceph_inode_info
*ci
,
203 const char *name
, int name_len
,
204 const char *val
, int val_len
,
206 int should_free_name
, int should_free_val
,
207 struct ceph_inode_xattr
**newxattr
)
210 struct rb_node
*parent
= NULL
;
211 struct ceph_inode_xattr
*xattr
= NULL
;
215 p
= &ci
->i_xattrs
.index
.rb_node
;
218 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
219 c
= strncmp(name
, xattr
->name
, min(name_len
, xattr
->name_len
));
225 if (name_len
== xattr
->name_len
)
227 else if (name_len
< xattr
->name_len
)
239 xattr
->name_len
= name_len
;
240 xattr
->should_free_name
= should_free_name
;
242 ci
->i_xattrs
.count
++;
243 dout("__set_xattr count=%d\n", ci
->i_xattrs
.count
);
247 if (xattr
->should_free_val
)
248 kfree((void *)xattr
->val
);
250 if (should_free_name
) {
254 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
255 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
257 ci
->i_xattrs
.names_size
+= name_len
;
258 ci
->i_xattrs
.vals_size
+= val_len
;
264 xattr
->val_len
= val_len
;
265 xattr
->dirty
= dirty
;
266 xattr
->should_free_val
= (val
&& should_free_val
);
269 rb_link_node(&xattr
->node
, parent
, p
);
270 rb_insert_color(&xattr
->node
, &ci
->i_xattrs
.index
);
271 dout("__set_xattr_val p=%p\n", p
);
274 dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
275 ceph_vinop(&ci
->vfs_inode
), xattr
, name
, val_len
, val
);
280 static struct ceph_inode_xattr
*__get_xattr(struct ceph_inode_info
*ci
,
284 struct rb_node
*parent
= NULL
;
285 struct ceph_inode_xattr
*xattr
= NULL
;
286 int name_len
= strlen(name
);
289 p
= &ci
->i_xattrs
.index
.rb_node
;
292 xattr
= rb_entry(parent
, struct ceph_inode_xattr
, node
);
293 c
= strncmp(name
, xattr
->name
, xattr
->name_len
);
294 if (c
== 0 && name_len
> xattr
->name_len
)
301 dout("__get_xattr %s: found %.*s\n", name
,
302 xattr
->val_len
, xattr
->val
);
307 dout("__get_xattr %s: not found\n", name
);
312 static void __free_xattr(struct ceph_inode_xattr
*xattr
)
316 if (xattr
->should_free_name
)
317 kfree((void *)xattr
->name
);
318 if (xattr
->should_free_val
)
319 kfree((void *)xattr
->val
);
324 static int __remove_xattr(struct ceph_inode_info
*ci
,
325 struct ceph_inode_xattr
*xattr
)
330 rb_erase(&xattr
->node
, &ci
->i_xattrs
.index
);
332 if (xattr
->should_free_name
)
333 kfree((void *)xattr
->name
);
334 if (xattr
->should_free_val
)
335 kfree((void *)xattr
->val
);
337 ci
->i_xattrs
.names_size
-= xattr
->name_len
;
338 ci
->i_xattrs
.vals_size
-= xattr
->val_len
;
339 ci
->i_xattrs
.count
--;
345 static int __remove_xattr_by_name(struct ceph_inode_info
*ci
,
349 struct ceph_inode_xattr
*xattr
;
352 p
= &ci
->i_xattrs
.index
.rb_node
;
353 xattr
= __get_xattr(ci
, name
);
354 err
= __remove_xattr(ci
, xattr
);
358 static char *__copy_xattr_names(struct ceph_inode_info
*ci
,
362 struct ceph_inode_xattr
*xattr
= NULL
;
364 p
= rb_first(&ci
->i_xattrs
.index
);
365 dout("__copy_xattr_names count=%d\n", ci
->i_xattrs
.count
);
368 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
369 memcpy(dest
, xattr
->name
, xattr
->name_len
);
370 dest
[xattr
->name_len
] = '\0';
372 dout("dest=%s %p (%s) (%d/%d)\n", dest
, xattr
, xattr
->name
,
373 xattr
->name_len
, ci
->i_xattrs
.names_size
);
375 dest
+= xattr
->name_len
+ 1;
382 void __ceph_destroy_xattrs(struct ceph_inode_info
*ci
)
384 struct rb_node
*p
, *tmp
;
385 struct ceph_inode_xattr
*xattr
= NULL
;
387 p
= rb_first(&ci
->i_xattrs
.index
);
389 dout("__ceph_destroy_xattrs p=%p\n", p
);
392 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
395 dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p
,
396 xattr
->name_len
, xattr
->name
);
397 rb_erase(tmp
, &ci
->i_xattrs
.index
);
402 ci
->i_xattrs
.names_size
= 0;
403 ci
->i_xattrs
.vals_size
= 0;
404 ci
->i_xattrs
.index_version
= 0;
405 ci
->i_xattrs
.count
= 0;
406 ci
->i_xattrs
.index
= RB_ROOT
;
409 static int __build_xattrs(struct inode
*inode
)
410 __releases(ci
->i_ceph_lock
)
411 __acquires(ci
->i_ceph_lock
)
417 const char *name
, *val
;
418 struct ceph_inode_info
*ci
= ceph_inode(inode
);
420 struct ceph_inode_xattr
**xattrs
= NULL
;
424 dout("__build_xattrs() len=%d\n",
425 ci
->i_xattrs
.blob
? (int)ci
->i_xattrs
.blob
->vec
.iov_len
: 0);
427 if (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)
428 return 0; /* already built */
430 __ceph_destroy_xattrs(ci
);
433 /* updated internal xattr rb tree */
434 if (ci
->i_xattrs
.blob
&& ci
->i_xattrs
.blob
->vec
.iov_len
> 4) {
435 p
= ci
->i_xattrs
.blob
->vec
.iov_base
;
436 end
= p
+ ci
->i_xattrs
.blob
->vec
.iov_len
;
437 ceph_decode_32_safe(&p
, end
, numattr
, bad
);
438 xattr_version
= ci
->i_xattrs
.version
;
439 spin_unlock(&ci
->i_ceph_lock
);
441 xattrs
= kcalloc(numattr
, sizeof(struct ceph_xattr
*),
446 memset(xattrs
, 0, numattr
*sizeof(struct ceph_xattr
*));
447 for (i
= 0; i
< numattr
; i
++) {
448 xattrs
[i
] = kmalloc(sizeof(struct ceph_inode_xattr
),
454 spin_lock(&ci
->i_ceph_lock
);
455 if (ci
->i_xattrs
.version
!= xattr_version
) {
456 /* lost a race, retry */
457 for (i
= 0; i
< numattr
; i
++)
464 ceph_decode_32_safe(&p
, end
, len
, bad
);
468 ceph_decode_32_safe(&p
, end
, len
, bad
);
472 err
= __set_xattr(ci
, name
, namelen
, val
, len
,
473 0, 0, 0, &xattrs
[numattr
]);
480 ci
->i_xattrs
.index_version
= ci
->i_xattrs
.version
;
481 ci
->i_xattrs
.dirty
= false;
485 spin_lock(&ci
->i_ceph_lock
);
488 for (i
= 0; i
< numattr
; i
++)
492 ci
->i_xattrs
.names_size
= 0;
496 static int __get_required_blob_size(struct ceph_inode_info
*ci
, int name_size
,
500 * 4 bytes for the length, and additional 4 bytes per each xattr name,
501 * 4 bytes per each value
503 int size
= 4 + ci
->i_xattrs
.count
*(4 + 4) +
504 ci
->i_xattrs
.names_size
+
505 ci
->i_xattrs
.vals_size
;
506 dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
507 ci
->i_xattrs
.count
, ci
->i_xattrs
.names_size
,
508 ci
->i_xattrs
.vals_size
);
511 size
+= 4 + 4 + name_size
+ val_size
;
517 * If there are dirty xattrs, reencode xattrs into the prealloc_blob
518 * and swap into place.
520 void __ceph_build_xattrs_blob(struct ceph_inode_info
*ci
)
523 struct ceph_inode_xattr
*xattr
= NULL
;
526 dout("__build_xattrs_blob %p\n", &ci
->vfs_inode
);
527 if (ci
->i_xattrs
.dirty
) {
528 int need
= __get_required_blob_size(ci
, 0, 0);
530 BUG_ON(need
> ci
->i_xattrs
.prealloc_blob
->alloc_len
);
532 p
= rb_first(&ci
->i_xattrs
.index
);
533 dest
= ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
535 ceph_encode_32(&dest
, ci
->i_xattrs
.count
);
537 xattr
= rb_entry(p
, struct ceph_inode_xattr
, node
);
539 ceph_encode_32(&dest
, xattr
->name_len
);
540 memcpy(dest
, xattr
->name
, xattr
->name_len
);
541 dest
+= xattr
->name_len
;
542 ceph_encode_32(&dest
, xattr
->val_len
);
543 memcpy(dest
, xattr
->val
, xattr
->val_len
);
544 dest
+= xattr
->val_len
;
549 /* adjust buffer len; it may be larger than we need */
550 ci
->i_xattrs
.prealloc_blob
->vec
.iov_len
=
551 dest
- ci
->i_xattrs
.prealloc_blob
->vec
.iov_base
;
553 if (ci
->i_xattrs
.blob
)
554 ceph_buffer_put(ci
->i_xattrs
.blob
);
555 ci
->i_xattrs
.blob
= ci
->i_xattrs
.prealloc_blob
;
556 ci
->i_xattrs
.prealloc_blob
= NULL
;
557 ci
->i_xattrs
.dirty
= false;
558 ci
->i_xattrs
.version
++;
562 ssize_t
ceph_getxattr(struct dentry
*dentry
, const char *name
, void *value
,
565 struct inode
*inode
= dentry
->d_inode
;
566 struct ceph_inode_info
*ci
= ceph_inode(inode
);
568 struct ceph_inode_xattr
*xattr
;
569 struct ceph_vxattr
*vxattr
= NULL
;
571 if (!ceph_is_valid_xattr(name
))
574 /* let's see if a virtual xattr was requested */
575 vxattr
= ceph_match_vxattr(inode
, name
);
577 spin_lock(&ci
->i_ceph_lock
);
578 dout("getxattr %p ver=%lld index_ver=%lld\n", inode
,
579 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
581 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
582 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
585 spin_unlock(&ci
->i_ceph_lock
);
586 /* get xattrs from mds (if we don't already have them) */
587 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
592 spin_lock(&ci
->i_ceph_lock
);
594 if (vxattr
&& vxattr
->readonly
) {
595 err
= vxattr
->getxattr_cb(ci
, value
, size
);
599 err
= __build_xattrs(inode
);
604 err
= -ENODATA
; /* == ENOATTR */
605 xattr
= __get_xattr(ci
, name
);
608 err
= vxattr
->getxattr_cb(ci
, value
, size
);
613 if (size
&& size
< xattr
->val_len
)
616 err
= xattr
->val_len
;
620 memcpy(value
, xattr
->val
, xattr
->val_len
);
623 spin_unlock(&ci
->i_ceph_lock
);
627 ssize_t
ceph_listxattr(struct dentry
*dentry
, char *names
, size_t size
)
629 struct inode
*inode
= dentry
->d_inode
;
630 struct ceph_inode_info
*ci
= ceph_inode(inode
);
631 struct ceph_vxattr
*vxattrs
= ceph_inode_vxattrs(inode
);
638 spin_lock(&ci
->i_ceph_lock
);
639 dout("listxattr %p ver=%lld index_ver=%lld\n", inode
,
640 ci
->i_xattrs
.version
, ci
->i_xattrs
.index_version
);
642 if (__ceph_caps_issued_mask(ci
, CEPH_CAP_XATTR_SHARED
, 1) &&
643 (ci
->i_xattrs
.index_version
>= ci
->i_xattrs
.version
)) {
646 spin_unlock(&ci
->i_ceph_lock
);
647 err
= ceph_do_getattr(inode
, CEPH_STAT_CAP_XATTR
);
652 spin_lock(&ci
->i_ceph_lock
);
654 err
= __build_xattrs(inode
);
660 * Start with virtual dir xattr names (if any) (including
661 * terminating '\0' characters for each).
663 vir_namelen
= ceph_vxattrs_name_size(vxattrs
);
665 /* adding 1 byte per each variable due to the null termination */
666 namelen
= vir_namelen
+ ci
->i_xattrs
.names_size
+ ci
->i_xattrs
.count
;
668 if (size
&& namelen
> size
)
675 names
= __copy_xattr_names(ci
, names
);
677 /* virtual xattr names, too */
679 for (i
= 0; vxattrs
[i
].name
; i
++) {
680 len
= sprintf(names
, "%s", vxattrs
[i
].name
);
685 spin_unlock(&ci
->i_ceph_lock
);
689 static int ceph_sync_setxattr(struct dentry
*dentry
, const char *name
,
690 const char *value
, size_t size
, int flags
)
692 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
693 struct inode
*inode
= dentry
->d_inode
;
694 struct ceph_inode_info
*ci
= ceph_inode(inode
);
695 struct inode
*parent_inode
;
696 struct ceph_mds_request
*req
;
697 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
700 struct page
**pages
= NULL
;
703 /* copy value into some pages */
704 nr_pages
= calc_pages_for(0, size
);
706 pages
= kmalloc(sizeof(pages
[0])*nr_pages
, GFP_NOFS
);
710 for (i
= 0; i
< nr_pages
; i
++) {
711 pages
[i
] = __page_cache_alloc(GFP_NOFS
);
716 kaddr
= kmap(pages
[i
]);
717 memcpy(kaddr
, value
+ i
*PAGE_CACHE_SIZE
,
718 min(PAGE_CACHE_SIZE
, size
-i
*PAGE_CACHE_SIZE
));
722 dout("setxattr value=%.*s\n", (int)size
, value
);
725 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_SETXATTR
,
731 req
->r_inode
= inode
;
733 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
735 req
->r_args
.setxattr
.flags
= cpu_to_le32(flags
);
736 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
738 req
->r_pages
= pages
;
739 req
->r_num_pages
= nr_pages
;
740 req
->r_data_len
= size
;
742 dout("xattr.ver (before): %lld\n", ci
->i_xattrs
.version
);
743 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
744 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
746 ceph_mdsc_put_request(req
);
747 dout("xattr.ver (after): %lld\n", ci
->i_xattrs
.version
);
751 for (i
= 0; i
< nr_pages
; i
++)
752 __free_page(pages
[i
]);
758 int ceph_setxattr(struct dentry
*dentry
, const char *name
,
759 const void *value
, size_t size
, int flags
)
761 struct inode
*inode
= dentry
->d_inode
;
762 struct ceph_vxattr
*vxattr
;
763 struct ceph_inode_info
*ci
= ceph_inode(inode
);
767 int name_len
= strlen(name
);
769 char *newname
= NULL
;
771 struct ceph_inode_xattr
*xattr
= NULL
;
772 int required_blob_size
;
774 if (ceph_snap(inode
) != CEPH_NOSNAP
)
777 if (!ceph_is_valid_xattr(name
))
780 vxattr
= ceph_match_vxattr(inode
, name
);
781 if (vxattr
&& vxattr
->readonly
)
784 /* preallocate memory for xattr name, value, index node */
786 newname
= kmemdup(name
, name_len
+ 1, GFP_NOFS
);
791 newval
= kmemdup(value
, val_len
, GFP_NOFS
);
796 xattr
= kmalloc(sizeof(struct ceph_inode_xattr
), GFP_NOFS
);
800 spin_lock(&ci
->i_ceph_lock
);
802 issued
= __ceph_caps_issued(ci
, NULL
);
803 dout("setxattr %p issued %s\n", inode
, ceph_cap_string(issued
));
804 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
806 __build_xattrs(inode
);
808 required_blob_size
= __get_required_blob_size(ci
, name_len
, val_len
);
810 if (!ci
->i_xattrs
.prealloc_blob
||
811 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
812 struct ceph_buffer
*blob
;
814 spin_unlock(&ci
->i_ceph_lock
);
815 dout(" preaallocating new blob size=%d\n", required_blob_size
);
816 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
819 spin_lock(&ci
->i_ceph_lock
);
820 if (ci
->i_xattrs
.prealloc_blob
)
821 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
822 ci
->i_xattrs
.prealloc_blob
= blob
;
826 err
= __set_xattr(ci
, newname
, name_len
, newval
,
827 val_len
, 1, 1, 1, &xattr
);
829 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
830 ci
->i_xattrs
.dirty
= true;
831 inode
->i_ctime
= CURRENT_TIME
;
833 spin_unlock(&ci
->i_ceph_lock
);
835 __mark_inode_dirty(inode
, dirty
);
839 spin_unlock(&ci
->i_ceph_lock
);
840 err
= ceph_sync_setxattr(dentry
, name
, value
, size
, flags
);
848 static int ceph_send_removexattr(struct dentry
*dentry
, const char *name
)
850 struct ceph_fs_client
*fsc
= ceph_sb_to_client(dentry
->d_sb
);
851 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
852 struct inode
*inode
= dentry
->d_inode
;
853 struct inode
*parent_inode
;
854 struct ceph_mds_request
*req
;
857 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_RMXATTR
,
861 req
->r_inode
= inode
;
863 req
->r_inode_drop
= CEPH_CAP_XATTR_SHARED
;
865 req
->r_path2
= kstrdup(name
, GFP_NOFS
);
867 parent_inode
= ceph_get_dentry_parent_inode(dentry
);
868 err
= ceph_mdsc_do_request(mdsc
, parent_inode
, req
);
870 ceph_mdsc_put_request(req
);
874 int ceph_removexattr(struct dentry
*dentry
, const char *name
)
876 struct inode
*inode
= dentry
->d_inode
;
877 struct ceph_vxattr
*vxattr
;
878 struct ceph_inode_info
*ci
= ceph_inode(inode
);
881 int required_blob_size
;
884 if (ceph_snap(inode
) != CEPH_NOSNAP
)
887 if (!ceph_is_valid_xattr(name
))
890 vxattr
= ceph_match_vxattr(inode
, name
);
891 if (vxattr
&& vxattr
->readonly
)
895 spin_lock(&ci
->i_ceph_lock
);
897 issued
= __ceph_caps_issued(ci
, NULL
);
898 dout("removexattr %p issued %s\n", inode
, ceph_cap_string(issued
));
900 if (!(issued
& CEPH_CAP_XATTR_EXCL
))
902 __build_xattrs(inode
);
904 required_blob_size
= __get_required_blob_size(ci
, 0, 0);
906 if (!ci
->i_xattrs
.prealloc_blob
||
907 required_blob_size
> ci
->i_xattrs
.prealloc_blob
->alloc_len
) {
908 struct ceph_buffer
*blob
;
910 spin_unlock(&ci
->i_ceph_lock
);
911 dout(" preaallocating new blob size=%d\n", required_blob_size
);
912 blob
= ceph_buffer_new(required_blob_size
, GFP_NOFS
);
915 spin_lock(&ci
->i_ceph_lock
);
916 if (ci
->i_xattrs
.prealloc_blob
)
917 ceph_buffer_put(ci
->i_xattrs
.prealloc_blob
);
918 ci
->i_xattrs
.prealloc_blob
= blob
;
922 err
= __remove_xattr_by_name(ceph_inode(inode
), name
);
924 dirty
= __ceph_mark_dirty_caps(ci
, CEPH_CAP_XATTR_EXCL
);
925 ci
->i_xattrs
.dirty
= true;
926 inode
->i_ctime
= CURRENT_TIME
;
927 spin_unlock(&ci
->i_ceph_lock
);
929 __mark_inode_dirty(inode
, dirty
);
932 spin_unlock(&ci
->i_ceph_lock
);
933 err
= ceph_send_removexattr(dentry
, name
);