blob: f3c4fe7202c71bf475c91f03108f2820923da119 [file] [log] [blame]
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001#include <linux/ceph/ceph_debug.h>
2
Sage Weil355da1e2009-10-06 11:31:08 -07003#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07004#include "mds_client.h"
5
6#include <linux/ceph/decode.h>
Sage Weil355da1e2009-10-06 11:31:08 -07007
8#include <linux/xattr.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Sage Weil355da1e2009-10-06 11:31:08 -070010
Alex Elder22891902012-01-23 15:49:28 -060011#define XATTR_CEPH_PREFIX "ceph."
12#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
13
Sage Weil355da1e2009-10-06 11:31:08 -070014static bool ceph_is_valid_xattr(const char *name)
15{
Alex Elder22891902012-01-23 15:49:28 -060016 return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
Sage Weil1a756272010-05-11 11:40:25 -070017 !strncmp(name, XATTR_SECURITY_PREFIX,
Sage Weil355da1e2009-10-06 11:31:08 -070018 XATTR_SECURITY_PREFIX_LEN) ||
19 !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
20 !strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
21}
22
23/*
24 * These define virtual xattrs exposing the recursive directory
25 * statistics and layout metadata.
26 */
Alex Elder881a5fa2012-01-23 15:49:28 -060027struct ceph_vxattr {
Sage Weil355da1e2009-10-06 11:31:08 -070028 char *name;
Alex Elder3ce6cd12012-01-23 15:49:28 -060029 size_t name_size; /* strlen(name) + 1 (for '\0') */
Sage Weil355da1e2009-10-06 11:31:08 -070030 size_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
31 size_t size);
Sage Weil88601472013-01-31 11:53:27 -080032 bool readonly, hidden;
Sage Weilf36e4472013-01-20 21:59:29 -080033 bool (*exists_cb)(struct ceph_inode_info *ci);
Sage Weil355da1e2009-10-06 11:31:08 -070034};
35
Sage Weil32ab0bd2013-01-19 16:46:32 -080036/* layouts */
37
38static bool ceph_vxattrcb_layout_exists(struct ceph_inode_info *ci)
39{
40 size_t s;
41 char *p = (char *)&ci->i_layout;
42
43 for (s = 0; s < sizeof(ci->i_layout); s++, p++)
44 if (*p)
45 return true;
46 return false;
47}
48
49static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
50 size_t size)
51{
52 int ret;
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;
57
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);
61 if (pool_name)
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),
67 pool_name);
68 else
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);
75
76 up_read(&osdc->map_sem);
77 return ret;
78}
79
Sage Weil355da1e2009-10-06 11:31:08 -070080/* directories */
81
Alex Elderaa4066e2012-01-23 15:49:28 -060082static size_t ceph_vxattrcb_dir_entries(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -070083 size_t size)
84{
85 return snprintf(val, size, "%lld", ci->i_files + ci->i_subdirs);
86}
87
Alex Elderaa4066e2012-01-23 15:49:28 -060088static size_t ceph_vxattrcb_dir_files(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -070089 size_t size)
90{
91 return snprintf(val, size, "%lld", ci->i_files);
92}
93
Alex Elderaa4066e2012-01-23 15:49:28 -060094static size_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -070095 size_t size)
96{
97 return snprintf(val, size, "%lld", ci->i_subdirs);
98}
99
Alex Elderaa4066e2012-01-23 15:49:28 -0600100static size_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -0700101 size_t size)
102{
103 return snprintf(val, size, "%lld", ci->i_rfiles + ci->i_rsubdirs);
104}
105
Alex Elderaa4066e2012-01-23 15:49:28 -0600106static size_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -0700107 size_t size)
108{
109 return snprintf(val, size, "%lld", ci->i_rfiles);
110}
111
Alex Elderaa4066e2012-01-23 15:49:28 -0600112static size_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -0700113 size_t size)
114{
115 return snprintf(val, size, "%lld", ci->i_rsubdirs);
116}
117
Alex Elderaa4066e2012-01-23 15:49:28 -0600118static size_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -0700119 size_t size)
120{
121 return snprintf(val, size, "%lld", ci->i_rbytes);
122}
123
Alex Elderaa4066e2012-01-23 15:49:28 -0600124static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
Sage Weil355da1e2009-10-06 11:31:08 -0700125 size_t size)
126{
Alex Elder3489b422012-03-08 16:50:09 -0600127 return snprintf(val, size, "%ld.09%ld", (long)ci->i_rctime.tv_sec,
Sage Weil355da1e2009-10-06 11:31:08 -0700128 (long)ci->i_rctime.tv_nsec);
129}
130
Sage Weil32ab0bd2013-01-19 16:46:32 -0800131
Alex Eldereb788082012-01-23 15:49:28 -0600132#define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
133
Sage Weil88601472013-01-31 11:53:27 -0800134#define XATTR_NAME_CEPH(_type, _name) \
135 { \
136 .name = CEPH_XATTR_NAME(_type, _name), \
137 .name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
138 .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
139 .readonly = true, \
140 .hidden = false, \
Sage Weilf36e4472013-01-20 21:59:29 -0800141 .exists_cb = NULL, \
Sage Weil88601472013-01-31 11:53:27 -0800142 }
Alex Eldereb788082012-01-23 15:49:28 -0600143
Alex Elder881a5fa2012-01-23 15:49:28 -0600144static struct ceph_vxattr ceph_dir_vxattrs[] = {
Sage Weil1f08f2b2013-01-20 22:07:12 -0800145 {
146 .name = "ceph.dir.layout",
147 .name_size = sizeof("ceph.dir.layout"),
148 .getxattr_cb = ceph_vxattrcb_layout,
149 .readonly = false,
150 .hidden = false,
151 .exists_cb = ceph_vxattrcb_layout_exists,
152 },
Alex Eldereb788082012-01-23 15:49:28 -0600153 XATTR_NAME_CEPH(dir, entries),
154 XATTR_NAME_CEPH(dir, files),
155 XATTR_NAME_CEPH(dir, subdirs),
156 XATTR_NAME_CEPH(dir, rentries),
157 XATTR_NAME_CEPH(dir, rfiles),
158 XATTR_NAME_CEPH(dir, rsubdirs),
159 XATTR_NAME_CEPH(dir, rbytes),
160 XATTR_NAME_CEPH(dir, rctime),
161 { 0 } /* Required table terminator */
Sage Weil355da1e2009-10-06 11:31:08 -0700162};
Alex Elder3ce6cd12012-01-23 15:49:28 -0600163static size_t ceph_dir_vxattrs_name_size; /* total size of all names */
Sage Weil355da1e2009-10-06 11:31:08 -0700164
165/* files */
166
Alex Elder881a5fa2012-01-23 15:49:28 -0600167static struct ceph_vxattr ceph_file_vxattrs[] = {
Sage Weil32ab0bd2013-01-19 16:46:32 -0800168 {
169 .name = "ceph.file.layout",
170 .name_size = sizeof("ceph.file.layout"),
171 .getxattr_cb = ceph_vxattrcb_layout,
172 .readonly = false,
173 .hidden = false,
174 .exists_cb = ceph_vxattrcb_layout_exists,
175 },
Alex Eldereb788082012-01-23 15:49:28 -0600176 { 0 } /* Required table terminator */
Sage Weil355da1e2009-10-06 11:31:08 -0700177};
Alex Elder3ce6cd12012-01-23 15:49:28 -0600178static size_t ceph_file_vxattrs_name_size; /* total size of all names */
Sage Weil355da1e2009-10-06 11:31:08 -0700179
Alex Elder881a5fa2012-01-23 15:49:28 -0600180static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
Sage Weil355da1e2009-10-06 11:31:08 -0700181{
182 if (S_ISDIR(inode->i_mode))
183 return ceph_dir_vxattrs;
184 else if (S_ISREG(inode->i_mode))
185 return ceph_file_vxattrs;
186 return NULL;
187}
188
Alex Elder3ce6cd12012-01-23 15:49:28 -0600189static size_t ceph_vxattrs_name_size(struct ceph_vxattr *vxattrs)
190{
191 if (vxattrs == ceph_dir_vxattrs)
192 return ceph_dir_vxattrs_name_size;
193 if (vxattrs == ceph_file_vxattrs)
194 return ceph_file_vxattrs_name_size;
195 BUG();
196
197 return 0;
198}
199
200/*
201 * Compute the aggregate size (including terminating '\0') of all
202 * virtual extended attribute names in the given vxattr table.
203 */
204static size_t __init vxattrs_name_size(struct ceph_vxattr *vxattrs)
205{
206 struct ceph_vxattr *vxattr;
207 size_t size = 0;
208
209 for (vxattr = vxattrs; vxattr->name; vxattr++)
Sage Weil88601472013-01-31 11:53:27 -0800210 if (!vxattr->hidden)
211 size += vxattr->name_size;
Alex Elder3ce6cd12012-01-23 15:49:28 -0600212
213 return size;
214}
215
216/* Routines called at initialization and exit time */
217
218void __init ceph_xattr_init(void)
219{
220 ceph_dir_vxattrs_name_size = vxattrs_name_size(ceph_dir_vxattrs);
221 ceph_file_vxattrs_name_size = vxattrs_name_size(ceph_file_vxattrs);
222}
223
224void ceph_xattr_exit(void)
225{
226 ceph_dir_vxattrs_name_size = 0;
227 ceph_file_vxattrs_name_size = 0;
228}
229
Alex Elder881a5fa2012-01-23 15:49:28 -0600230static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
Sage Weil355da1e2009-10-06 11:31:08 -0700231 const char *name)
232{
Alex Elder881a5fa2012-01-23 15:49:28 -0600233 struct ceph_vxattr *vxattr = ceph_inode_vxattrs(inode);
Alex Elder06476a62012-01-23 15:49:27 -0600234
235 if (vxattr) {
236 while (vxattr->name) {
237 if (!strcmp(vxattr->name, name))
238 return vxattr;
239 vxattr++;
240 }
241 }
242
Sage Weil355da1e2009-10-06 11:31:08 -0700243 return NULL;
244}
245
246static int __set_xattr(struct ceph_inode_info *ci,
247 const char *name, int name_len,
248 const char *val, int val_len,
249 int dirty,
250 int should_free_name, int should_free_val,
251 struct ceph_inode_xattr **newxattr)
252{
253 struct rb_node **p;
254 struct rb_node *parent = NULL;
255 struct ceph_inode_xattr *xattr = NULL;
256 int c;
257 int new = 0;
258
259 p = &ci->i_xattrs.index.rb_node;
260 while (*p) {
261 parent = *p;
262 xattr = rb_entry(parent, struct ceph_inode_xattr, node);
263 c = strncmp(name, xattr->name, min(name_len, xattr->name_len));
264 if (c < 0)
265 p = &(*p)->rb_left;
266 else if (c > 0)
267 p = &(*p)->rb_right;
268 else {
269 if (name_len == xattr->name_len)
270 break;
271 else if (name_len < xattr->name_len)
272 p = &(*p)->rb_left;
273 else
274 p = &(*p)->rb_right;
275 }
276 xattr = NULL;
277 }
278
279 if (!xattr) {
280 new = 1;
281 xattr = *newxattr;
282 xattr->name = name;
283 xattr->name_len = name_len;
284 xattr->should_free_name = should_free_name;
285
286 ci->i_xattrs.count++;
287 dout("__set_xattr count=%d\n", ci->i_xattrs.count);
288 } else {
289 kfree(*newxattr);
290 *newxattr = NULL;
291 if (xattr->should_free_val)
292 kfree((void *)xattr->val);
293
294 if (should_free_name) {
295 kfree((void *)name);
296 name = xattr->name;
297 }
298 ci->i_xattrs.names_size -= xattr->name_len;
299 ci->i_xattrs.vals_size -= xattr->val_len;
300 }
Sage Weil355da1e2009-10-06 11:31:08 -0700301 ci->i_xattrs.names_size += name_len;
302 ci->i_xattrs.vals_size += val_len;
303 if (val)
304 xattr->val = val;
305 else
306 xattr->val = "";
307
308 xattr->val_len = val_len;
309 xattr->dirty = dirty;
310 xattr->should_free_val = (val && should_free_val);
311
312 if (new) {
313 rb_link_node(&xattr->node, parent, p);
314 rb_insert_color(&xattr->node, &ci->i_xattrs.index);
315 dout("__set_xattr_val p=%p\n", p);
316 }
317
318 dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
319 ceph_vinop(&ci->vfs_inode), xattr, name, val_len, val);
320
321 return 0;
322}
323
324static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,
325 const char *name)
326{
327 struct rb_node **p;
328 struct rb_node *parent = NULL;
329 struct ceph_inode_xattr *xattr = NULL;
Sage Weil17db1432011-01-13 15:27:29 -0800330 int name_len = strlen(name);
Sage Weil355da1e2009-10-06 11:31:08 -0700331 int c;
332
333 p = &ci->i_xattrs.index.rb_node;
334 while (*p) {
335 parent = *p;
336 xattr = rb_entry(parent, struct ceph_inode_xattr, node);
337 c = strncmp(name, xattr->name, xattr->name_len);
Sage Weil17db1432011-01-13 15:27:29 -0800338 if (c == 0 && name_len > xattr->name_len)
339 c = 1;
Sage Weil355da1e2009-10-06 11:31:08 -0700340 if (c < 0)
341 p = &(*p)->rb_left;
342 else if (c > 0)
343 p = &(*p)->rb_right;
344 else {
345 dout("__get_xattr %s: found %.*s\n", name,
346 xattr->val_len, xattr->val);
347 return xattr;
348 }
349 }
350
351 dout("__get_xattr %s: not found\n", name);
352
353 return NULL;
354}
355
356static void __free_xattr(struct ceph_inode_xattr *xattr)
357{
358 BUG_ON(!xattr);
359
360 if (xattr->should_free_name)
361 kfree((void *)xattr->name);
362 if (xattr->should_free_val)
363 kfree((void *)xattr->val);
364
365 kfree(xattr);
366}
367
368static int __remove_xattr(struct ceph_inode_info *ci,
369 struct ceph_inode_xattr *xattr)
370{
371 if (!xattr)
372 return -EOPNOTSUPP;
373
374 rb_erase(&xattr->node, &ci->i_xattrs.index);
375
376 if (xattr->should_free_name)
377 kfree((void *)xattr->name);
378 if (xattr->should_free_val)
379 kfree((void *)xattr->val);
380
381 ci->i_xattrs.names_size -= xattr->name_len;
382 ci->i_xattrs.vals_size -= xattr->val_len;
383 ci->i_xattrs.count--;
384 kfree(xattr);
385
386 return 0;
387}
388
389static int __remove_xattr_by_name(struct ceph_inode_info *ci,
390 const char *name)
391{
392 struct rb_node **p;
393 struct ceph_inode_xattr *xattr;
394 int err;
395
396 p = &ci->i_xattrs.index.rb_node;
397 xattr = __get_xattr(ci, name);
398 err = __remove_xattr(ci, xattr);
399 return err;
400}
401
402static char *__copy_xattr_names(struct ceph_inode_info *ci,
403 char *dest)
404{
405 struct rb_node *p;
406 struct ceph_inode_xattr *xattr = NULL;
407
408 p = rb_first(&ci->i_xattrs.index);
409 dout("__copy_xattr_names count=%d\n", ci->i_xattrs.count);
410
411 while (p) {
412 xattr = rb_entry(p, struct ceph_inode_xattr, node);
413 memcpy(dest, xattr->name, xattr->name_len);
414 dest[xattr->name_len] = '\0';
415
416 dout("dest=%s %p (%s) (%d/%d)\n", dest, xattr, xattr->name,
417 xattr->name_len, ci->i_xattrs.names_size);
418
419 dest += xattr->name_len + 1;
420 p = rb_next(p);
421 }
422
423 return dest;
424}
425
426void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
427{
428 struct rb_node *p, *tmp;
429 struct ceph_inode_xattr *xattr = NULL;
430
431 p = rb_first(&ci->i_xattrs.index);
432
433 dout("__ceph_destroy_xattrs p=%p\n", p);
434
435 while (p) {
436 xattr = rb_entry(p, struct ceph_inode_xattr, node);
437 tmp = p;
438 p = rb_next(tmp);
439 dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p,
440 xattr->name_len, xattr->name);
441 rb_erase(tmp, &ci->i_xattrs.index);
442
443 __free_xattr(xattr);
444 }
445
446 ci->i_xattrs.names_size = 0;
447 ci->i_xattrs.vals_size = 0;
448 ci->i_xattrs.index_version = 0;
449 ci->i_xattrs.count = 0;
450 ci->i_xattrs.index = RB_ROOT;
451}
452
453static int __build_xattrs(struct inode *inode)
Sage Weilbe655592011-11-30 09:47:09 -0800454 __releases(ci->i_ceph_lock)
455 __acquires(ci->i_ceph_lock)
Sage Weil355da1e2009-10-06 11:31:08 -0700456{
457 u32 namelen;
458 u32 numattr = 0;
459 void *p, *end;
460 u32 len;
461 const char *name, *val;
462 struct ceph_inode_info *ci = ceph_inode(inode);
463 int xattr_version;
464 struct ceph_inode_xattr **xattrs = NULL;
Sage Weil63ff78b2009-11-01 17:51:15 -0800465 int err = 0;
Sage Weil355da1e2009-10-06 11:31:08 -0700466 int i;
467
468 dout("__build_xattrs() len=%d\n",
469 ci->i_xattrs.blob ? (int)ci->i_xattrs.blob->vec.iov_len : 0);
470
471 if (ci->i_xattrs.index_version >= ci->i_xattrs.version)
472 return 0; /* already built */
473
474 __ceph_destroy_xattrs(ci);
475
476start:
477 /* updated internal xattr rb tree */
478 if (ci->i_xattrs.blob && ci->i_xattrs.blob->vec.iov_len > 4) {
479 p = ci->i_xattrs.blob->vec.iov_base;
480 end = p + ci->i_xattrs.blob->vec.iov_len;
481 ceph_decode_32_safe(&p, end, numattr, bad);
482 xattr_version = ci->i_xattrs.version;
Sage Weilbe655592011-11-30 09:47:09 -0800483 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700484
485 xattrs = kcalloc(numattr, sizeof(struct ceph_xattr *),
486 GFP_NOFS);
487 err = -ENOMEM;
488 if (!xattrs)
489 goto bad_lock;
490 memset(xattrs, 0, numattr*sizeof(struct ceph_xattr *));
491 for (i = 0; i < numattr; i++) {
492 xattrs[i] = kmalloc(sizeof(struct ceph_inode_xattr),
493 GFP_NOFS);
494 if (!xattrs[i])
495 goto bad_lock;
496 }
497
Sage Weilbe655592011-11-30 09:47:09 -0800498 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700499 if (ci->i_xattrs.version != xattr_version) {
500 /* lost a race, retry */
501 for (i = 0; i < numattr; i++)
502 kfree(xattrs[i]);
503 kfree(xattrs);
Alan Cox21ec6ff2012-07-20 08:18:36 -0500504 xattrs = NULL;
Sage Weil355da1e2009-10-06 11:31:08 -0700505 goto start;
506 }
507 err = -EIO;
508 while (numattr--) {
509 ceph_decode_32_safe(&p, end, len, bad);
510 namelen = len;
511 name = p;
512 p += len;
513 ceph_decode_32_safe(&p, end, len, bad);
514 val = p;
515 p += len;
516
517 err = __set_xattr(ci, name, namelen, val, len,
518 0, 0, 0, &xattrs[numattr]);
519
520 if (err < 0)
521 goto bad;
522 }
523 kfree(xattrs);
524 }
525 ci->i_xattrs.index_version = ci->i_xattrs.version;
526 ci->i_xattrs.dirty = false;
527
528 return err;
529bad_lock:
Sage Weilbe655592011-11-30 09:47:09 -0800530 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700531bad:
532 if (xattrs) {
533 for (i = 0; i < numattr; i++)
534 kfree(xattrs[i]);
535 kfree(xattrs);
536 }
537 ci->i_xattrs.names_size = 0;
538 return err;
539}
540
541static int __get_required_blob_size(struct ceph_inode_info *ci, int name_size,
542 int val_size)
543{
544 /*
545 * 4 bytes for the length, and additional 4 bytes per each xattr name,
546 * 4 bytes per each value
547 */
548 int size = 4 + ci->i_xattrs.count*(4 + 4) +
549 ci->i_xattrs.names_size +
550 ci->i_xattrs.vals_size;
551 dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
552 ci->i_xattrs.count, ci->i_xattrs.names_size,
553 ci->i_xattrs.vals_size);
554
555 if (name_size)
556 size += 4 + 4 + name_size + val_size;
557
558 return size;
559}
560
561/*
562 * If there are dirty xattrs, reencode xattrs into the prealloc_blob
563 * and swap into place.
564 */
565void __ceph_build_xattrs_blob(struct ceph_inode_info *ci)
566{
567 struct rb_node *p;
568 struct ceph_inode_xattr *xattr = NULL;
569 void *dest;
570
571 dout("__build_xattrs_blob %p\n", &ci->vfs_inode);
572 if (ci->i_xattrs.dirty) {
573 int need = __get_required_blob_size(ci, 0, 0);
574
575 BUG_ON(need > ci->i_xattrs.prealloc_blob->alloc_len);
576
577 p = rb_first(&ci->i_xattrs.index);
578 dest = ci->i_xattrs.prealloc_blob->vec.iov_base;
579
580 ceph_encode_32(&dest, ci->i_xattrs.count);
581 while (p) {
582 xattr = rb_entry(p, struct ceph_inode_xattr, node);
583
584 ceph_encode_32(&dest, xattr->name_len);
585 memcpy(dest, xattr->name, xattr->name_len);
586 dest += xattr->name_len;
587 ceph_encode_32(&dest, xattr->val_len);
588 memcpy(dest, xattr->val, xattr->val_len);
589 dest += xattr->val_len;
590
591 p = rb_next(p);
592 }
593
594 /* adjust buffer len; it may be larger than we need */
595 ci->i_xattrs.prealloc_blob->vec.iov_len =
596 dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
597
Sage Weilb6c1d5b2009-12-07 12:17:17 -0800598 if (ci->i_xattrs.blob)
599 ceph_buffer_put(ci->i_xattrs.blob);
Sage Weil355da1e2009-10-06 11:31:08 -0700600 ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
601 ci->i_xattrs.prealloc_blob = NULL;
602 ci->i_xattrs.dirty = false;
Sage Weil4a625be2010-08-22 15:03:56 -0700603 ci->i_xattrs.version++;
Sage Weil355da1e2009-10-06 11:31:08 -0700604 }
605}
606
607ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
608 size_t size)
609{
610 struct inode *inode = dentry->d_inode;
611 struct ceph_inode_info *ci = ceph_inode(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700612 int err;
613 struct ceph_inode_xattr *xattr;
Alex Elder881a5fa2012-01-23 15:49:28 -0600614 struct ceph_vxattr *vxattr = NULL;
Sage Weil355da1e2009-10-06 11:31:08 -0700615
616 if (!ceph_is_valid_xattr(name))
617 return -ENODATA;
618
Sage Weilbe655592011-11-30 09:47:09 -0800619 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700620 dout("getxattr %p ver=%lld index_ver=%lld\n", inode,
621 ci->i_xattrs.version, ci->i_xattrs.index_version);
622
Sage Weil0bee82f2013-01-20 22:00:58 -0800623 /* let's see if a virtual xattr was requested */
624 vxattr = ceph_match_vxattr(inode, name);
625 if (vxattr && !(vxattr->exists_cb && !vxattr->exists_cb(ci))) {
626 err = vxattr->getxattr_cb(ci, value, size);
627 goto out;
628 }
629
Sage Weil355da1e2009-10-06 11:31:08 -0700630 if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1) &&
631 (ci->i_xattrs.index_version >= ci->i_xattrs.version)) {
632 goto get_xattr;
633 } else {
Sage Weilbe655592011-11-30 09:47:09 -0800634 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700635 /* get xattrs from mds (if we don't already have them) */
636 err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR);
637 if (err)
638 return err;
639 }
640
Sage Weilbe655592011-11-30 09:47:09 -0800641 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700642
Sage Weil355da1e2009-10-06 11:31:08 -0700643 err = __build_xattrs(inode);
644 if (err < 0)
645 goto out;
646
647get_xattr:
648 err = -ENODATA; /* == ENOATTR */
649 xattr = __get_xattr(ci, name);
Sage Weil0bee82f2013-01-20 22:00:58 -0800650 if (!xattr)
Sage Weil355da1e2009-10-06 11:31:08 -0700651 goto out;
Sage Weil355da1e2009-10-06 11:31:08 -0700652
653 err = -ERANGE;
654 if (size && size < xattr->val_len)
655 goto out;
656
657 err = xattr->val_len;
658 if (size == 0)
659 goto out;
660
661 memcpy(value, xattr->val, xattr->val_len);
662
663out:
Sage Weilbe655592011-11-30 09:47:09 -0800664 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700665 return err;
666}
667
668ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
669{
670 struct inode *inode = dentry->d_inode;
671 struct ceph_inode_info *ci = ceph_inode(inode);
Alex Elder881a5fa2012-01-23 15:49:28 -0600672 struct ceph_vxattr *vxattrs = ceph_inode_vxattrs(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700673 u32 vir_namelen = 0;
674 u32 namelen;
675 int err;
676 u32 len;
677 int i;
678
Sage Weilbe655592011-11-30 09:47:09 -0800679 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700680 dout("listxattr %p ver=%lld index_ver=%lld\n", inode,
681 ci->i_xattrs.version, ci->i_xattrs.index_version);
682
683 if (__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1) &&
Henry C Changbddfa3c2010-04-29 09:32:28 -0700684 (ci->i_xattrs.index_version >= ci->i_xattrs.version)) {
Sage Weil355da1e2009-10-06 11:31:08 -0700685 goto list_xattr;
686 } else {
Sage Weilbe655592011-11-30 09:47:09 -0800687 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700688 err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR);
689 if (err)
690 return err;
691 }
692
Sage Weilbe655592011-11-30 09:47:09 -0800693 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700694
695 err = __build_xattrs(inode);
696 if (err < 0)
697 goto out;
698
699list_xattr:
Alex Elder3ce6cd12012-01-23 15:49:28 -0600700 /*
701 * Start with virtual dir xattr names (if any) (including
702 * terminating '\0' characters for each).
703 */
704 vir_namelen = ceph_vxattrs_name_size(vxattrs);
705
Sage Weil355da1e2009-10-06 11:31:08 -0700706 /* adding 1 byte per each variable due to the null termination */
Sage Weilb65917d2013-01-20 22:02:39 -0800707 namelen = ci->i_xattrs.names_size + ci->i_xattrs.count;
Sage Weil355da1e2009-10-06 11:31:08 -0700708 err = -ERANGE;
Sage Weilb65917d2013-01-20 22:02:39 -0800709 if (size && vir_namelen + namelen > size)
Sage Weil355da1e2009-10-06 11:31:08 -0700710 goto out;
711
Sage Weilb65917d2013-01-20 22:02:39 -0800712 err = namelen + vir_namelen;
Sage Weil355da1e2009-10-06 11:31:08 -0700713 if (size == 0)
714 goto out;
715
716 names = __copy_xattr_names(ci, names);
717
718 /* virtual xattr names, too */
Sage Weilb65917d2013-01-20 22:02:39 -0800719 err = namelen;
720 if (vxattrs) {
Sage Weil355da1e2009-10-06 11:31:08 -0700721 for (i = 0; vxattrs[i].name; i++) {
Sage Weilb65917d2013-01-20 22:02:39 -0800722 if (!vxattrs[i].hidden &&
723 !(vxattrs[i].exists_cb &&
724 !vxattrs[i].exists_cb(ci))) {
725 len = sprintf(names, "%s", vxattrs[i].name);
726 names += len + 1;
727 err += len + 1;
728 }
Sage Weil355da1e2009-10-06 11:31:08 -0700729 }
Sage Weilb65917d2013-01-20 22:02:39 -0800730 }
Sage Weil355da1e2009-10-06 11:31:08 -0700731
732out:
Sage Weilbe655592011-11-30 09:47:09 -0800733 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700734 return err;
735}
736
737static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
738 const char *value, size_t size, int flags)
739{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700740 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
Sage Weil355da1e2009-10-06 11:31:08 -0700741 struct inode *inode = dentry->d_inode;
742 struct ceph_inode_info *ci = ceph_inode(inode);
Sage Weil5f21c962011-07-26 11:30:29 -0700743 struct inode *parent_inode;
Sage Weil355da1e2009-10-06 11:31:08 -0700744 struct ceph_mds_request *req;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700745 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil355da1e2009-10-06 11:31:08 -0700746 int err;
747 int i, nr_pages;
748 struct page **pages = NULL;
749 void *kaddr;
750
751 /* copy value into some pages */
752 nr_pages = calc_pages_for(0, size);
753 if (nr_pages) {
754 pages = kmalloc(sizeof(pages[0])*nr_pages, GFP_NOFS);
755 if (!pages)
756 return -ENOMEM;
757 err = -ENOMEM;
758 for (i = 0; i < nr_pages; i++) {
Yehuda Sadeh31459fe2010-03-17 13:54:02 -0700759 pages[i] = __page_cache_alloc(GFP_NOFS);
Sage Weil355da1e2009-10-06 11:31:08 -0700760 if (!pages[i]) {
761 nr_pages = i;
762 goto out;
763 }
764 kaddr = kmap(pages[i]);
765 memcpy(kaddr, value + i*PAGE_CACHE_SIZE,
766 min(PAGE_CACHE_SIZE, size-i*PAGE_CACHE_SIZE));
767 }
768 }
769
770 dout("setxattr value=%.*s\n", (int)size, value);
771
772 /* do request */
773 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
774 USE_AUTH_MDS);
Julia Lawall60d87732009-11-21 12:53:08 +0100775 if (IS_ERR(req)) {
776 err = PTR_ERR(req);
777 goto out;
778 }
Sage Weil70b666c2011-05-27 09:24:26 -0700779 req->r_inode = inode;
780 ihold(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700781 req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
782 req->r_num_caps = 1;
783 req->r_args.setxattr.flags = cpu_to_le32(flags);
784 req->r_path2 = kstrdup(name, GFP_NOFS);
785
786 req->r_pages = pages;
787 req->r_num_pages = nr_pages;
788 req->r_data_len = size;
789
790 dout("xattr.ver (before): %lld\n", ci->i_xattrs.version);
Sage Weil5f21c962011-07-26 11:30:29 -0700791 parent_inode = ceph_get_dentry_parent_inode(dentry);
Sage Weil355da1e2009-10-06 11:31:08 -0700792 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
Sage Weil5f21c962011-07-26 11:30:29 -0700793 iput(parent_inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700794 ceph_mdsc_put_request(req);
795 dout("xattr.ver (after): %lld\n", ci->i_xattrs.version);
796
797out:
798 if (pages) {
799 for (i = 0; i < nr_pages; i++)
800 __free_page(pages[i]);
801 kfree(pages);
802 }
803 return err;
804}
805
806int ceph_setxattr(struct dentry *dentry, const char *name,
807 const void *value, size_t size, int flags)
808{
809 struct inode *inode = dentry->d_inode;
Alex Elder881a5fa2012-01-23 15:49:28 -0600810 struct ceph_vxattr *vxattr;
Sage Weil355da1e2009-10-06 11:31:08 -0700811 struct ceph_inode_info *ci = ceph_inode(inode);
Alex Elder18fa8b32012-01-23 15:49:28 -0600812 int issued;
Sage Weil355da1e2009-10-06 11:31:08 -0700813 int err;
Alex Elder18fa8b32012-01-23 15:49:28 -0600814 int dirty;
Sage Weil355da1e2009-10-06 11:31:08 -0700815 int name_len = strlen(name);
816 int val_len = size;
817 char *newname = NULL;
818 char *newval = NULL;
819 struct ceph_inode_xattr *xattr = NULL;
Sage Weil355da1e2009-10-06 11:31:08 -0700820 int required_blob_size;
821
822 if (ceph_snap(inode) != CEPH_NOSNAP)
823 return -EROFS;
824
825 if (!ceph_is_valid_xattr(name))
826 return -EOPNOTSUPP;
827
Alex Elder06476a62012-01-23 15:49:27 -0600828 vxattr = ceph_match_vxattr(inode, name);
829 if (vxattr && vxattr->readonly)
830 return -EOPNOTSUPP;
Sage Weil355da1e2009-10-06 11:31:08 -0700831
Sage Weil3adf6542013-01-31 11:53:41 -0800832 /* pass any unhandled ceph.* xattrs through to the MDS */
833 if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
834 goto do_sync_unlocked;
835
Sage Weil355da1e2009-10-06 11:31:08 -0700836 /* preallocate memory for xattr name, value, index node */
837 err = -ENOMEM;
Julia Lawall61413c22010-10-17 21:55:21 +0200838 newname = kmemdup(name, name_len + 1, GFP_NOFS);
Sage Weil355da1e2009-10-06 11:31:08 -0700839 if (!newname)
840 goto out;
Sage Weil355da1e2009-10-06 11:31:08 -0700841
842 if (val_len) {
Alex Elderb829c192012-01-23 15:49:27 -0600843 newval = kmemdup(value, val_len, GFP_NOFS);
Sage Weil355da1e2009-10-06 11:31:08 -0700844 if (!newval)
845 goto out;
Sage Weil355da1e2009-10-06 11:31:08 -0700846 }
847
848 xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
849 if (!xattr)
850 goto out;
851
Sage Weilbe655592011-11-30 09:47:09 -0800852 spin_lock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700853retry:
854 issued = __ceph_caps_issued(ci, NULL);
Alex Elder18fa8b32012-01-23 15:49:28 -0600855 dout("setxattr %p issued %s\n", inode, ceph_cap_string(issued));
Sage Weil355da1e2009-10-06 11:31:08 -0700856 if (!(issued & CEPH_CAP_XATTR_EXCL))
857 goto do_sync;
858 __build_xattrs(inode);
859
860 required_blob_size = __get_required_blob_size(ci, name_len, val_len);
861
862 if (!ci->i_xattrs.prealloc_blob ||
863 required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
Alex Elder18fa8b32012-01-23 15:49:28 -0600864 struct ceph_buffer *blob;
Sage Weil355da1e2009-10-06 11:31:08 -0700865
Sage Weilbe655592011-11-30 09:47:09 -0800866 spin_unlock(&ci->i_ceph_lock);
Sage Weil355da1e2009-10-06 11:31:08 -0700867 dout(" preaallocating new blob size=%d\n", required_blob_size);
Sage Weilb6c1d5b2009-12-07 12:17:17 -0800868 blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
Sage Weil355da1e2009-10-06 11:31:08 -0700869 if (!blob)
870 goto out;
Sage Weilbe655592011-11-30 09:47:09 -0800871 spin_lock(&ci->i_ceph_lock);
Sage Weilb6c1d5b2009-12-07 12:17:17 -0800872 if (ci->i_xattrs.prealloc_blob)
873 ceph_buffer_put(ci->i_xattrs.prealloc_blob);
Sage Weil355da1e2009-10-06 11:31:08 -0700874 ci->i_xattrs.prealloc_blob = blob;
875 goto retry;
876 }
877
Sage Weil355da1e2009-10-06 11:31:08 -0700878 err = __set_xattr(ci, newname, name_len, newval,
879 val_len, 1, 1, 1, &xattr);
Alex Elder18fa8b32012-01-23 15:49:28 -0600880
Sage Weilfca65b42011-05-04 11:33:47 -0700881 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
Sage Weil355da1e2009-10-06 11:31:08 -0700882 ci->i_xattrs.dirty = true;
883 inode->i_ctime = CURRENT_TIME;
Alex Elder18fa8b32012-01-23 15:49:28 -0600884
Sage Weilbe655592011-11-30 09:47:09 -0800885 spin_unlock(&ci->i_ceph_lock);
Sage Weilfca65b42011-05-04 11:33:47 -0700886 if (dirty)
887 __mark_inode_dirty(inode, dirty);
Sage Weil355da1e2009-10-06 11:31:08 -0700888 return err;
889
890do_sync:
Sage Weilbe655592011-11-30 09:47:09 -0800891 spin_unlock(&ci->i_ceph_lock);
Sage Weil3adf6542013-01-31 11:53:41 -0800892do_sync_unlocked:
Sage Weil355da1e2009-10-06 11:31:08 -0700893 err = ceph_sync_setxattr(dentry, name, value, size, flags);
894out:
895 kfree(newname);
896 kfree(newval);
897 kfree(xattr);
898 return err;
899}
900
901static int ceph_send_removexattr(struct dentry *dentry, const char *name)
902{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700903 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
904 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil355da1e2009-10-06 11:31:08 -0700905 struct inode *inode = dentry->d_inode;
Sage Weil5f21c962011-07-26 11:30:29 -0700906 struct inode *parent_inode;
Sage Weil355da1e2009-10-06 11:31:08 -0700907 struct ceph_mds_request *req;
908 int err;
909
910 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_RMXATTR,
911 USE_AUTH_MDS);
912 if (IS_ERR(req))
913 return PTR_ERR(req);
Sage Weil70b666c2011-05-27 09:24:26 -0700914 req->r_inode = inode;
915 ihold(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700916 req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
917 req->r_num_caps = 1;
918 req->r_path2 = kstrdup(name, GFP_NOFS);
919
Sage Weil5f21c962011-07-26 11:30:29 -0700920 parent_inode = ceph_get_dentry_parent_inode(dentry);
Sage Weil355da1e2009-10-06 11:31:08 -0700921 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
Sage Weil5f21c962011-07-26 11:30:29 -0700922 iput(parent_inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700923 ceph_mdsc_put_request(req);
924 return err;
925}
926
927int ceph_removexattr(struct dentry *dentry, const char *name)
928{
929 struct inode *inode = dentry->d_inode;
Alex Elder881a5fa2012-01-23 15:49:28 -0600930 struct ceph_vxattr *vxattr;
Sage Weil355da1e2009-10-06 11:31:08 -0700931 struct ceph_inode_info *ci = ceph_inode(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700932 int issued;
933 int err;
Alex Elder83eb26a2012-01-11 17:41:01 -0800934 int required_blob_size;
Sage Weilfca65b42011-05-04 11:33:47 -0700935 int dirty;
Sage Weil355da1e2009-10-06 11:31:08 -0700936
937 if (ceph_snap(inode) != CEPH_NOSNAP)
938 return -EROFS;
939
940 if (!ceph_is_valid_xattr(name))
941 return -EOPNOTSUPP;
942
Alex Elder06476a62012-01-23 15:49:27 -0600943 vxattr = ceph_match_vxattr(inode, name);
944 if (vxattr && vxattr->readonly)
945 return -EOPNOTSUPP;
Sage Weil355da1e2009-10-06 11:31:08 -0700946
Sage Weild421acb2013-01-20 21:55:30 -0800947 /* pass any unhandled ceph.* xattrs through to the MDS */
948 if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
949 goto do_sync_unlocked;
950
Alex Elder83eb26a2012-01-11 17:41:01 -0800951 err = -ENOMEM;
Sage Weilbe655592011-11-30 09:47:09 -0800952 spin_lock(&ci->i_ceph_lock);
Alex Elder83eb26a2012-01-11 17:41:01 -0800953retry:
Sage Weil355da1e2009-10-06 11:31:08 -0700954 issued = __ceph_caps_issued(ci, NULL);
955 dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued));
956
957 if (!(issued & CEPH_CAP_XATTR_EXCL))
958 goto do_sync;
Alex Elder18fa8b32012-01-23 15:49:28 -0600959 __build_xattrs(inode);
Sage Weil355da1e2009-10-06 11:31:08 -0700960
Alex Elder83eb26a2012-01-11 17:41:01 -0800961 required_blob_size = __get_required_blob_size(ci, 0, 0);
962
963 if (!ci->i_xattrs.prealloc_blob ||
964 required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
965 struct ceph_buffer *blob;
966
967 spin_unlock(&ci->i_ceph_lock);
968 dout(" preaallocating new blob size=%d\n", required_blob_size);
969 blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
970 if (!blob)
971 goto out;
972 spin_lock(&ci->i_ceph_lock);
973 if (ci->i_xattrs.prealloc_blob)
974 ceph_buffer_put(ci->i_xattrs.prealloc_blob);
975 ci->i_xattrs.prealloc_blob = blob;
976 goto retry;
977 }
978
Sage Weil355da1e2009-10-06 11:31:08 -0700979 err = __remove_xattr_by_name(ceph_inode(inode), name);
Alex Elder18fa8b32012-01-23 15:49:28 -0600980
Sage Weilfca65b42011-05-04 11:33:47 -0700981 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
Sage Weil355da1e2009-10-06 11:31:08 -0700982 ci->i_xattrs.dirty = true;
983 inode->i_ctime = CURRENT_TIME;
Sage Weilbe655592011-11-30 09:47:09 -0800984 spin_unlock(&ci->i_ceph_lock);
Sage Weilfca65b42011-05-04 11:33:47 -0700985 if (dirty)
986 __mark_inode_dirty(inode, dirty);
Sage Weil355da1e2009-10-06 11:31:08 -0700987 return err;
988do_sync:
Sage Weilbe655592011-11-30 09:47:09 -0800989 spin_unlock(&ci->i_ceph_lock);
Sage Weild421acb2013-01-20 21:55:30 -0800990do_sync_unlocked:
Sage Weil355da1e2009-10-06 11:31:08 -0700991 err = ceph_send_removexattr(dentry, name);
Alex Elder83eb26a2012-01-11 17:41:01 -0800992out:
Sage Weil355da1e2009-10-06 11:31:08 -0700993 return err;
994}
995