blob: 2bbb5fff26a034cbd34e15ab2abb193830ab7380 [file] [log] [blame]
Linus Torvalds8005ecc2012-12-20 13:54:51 -08001/*
2 * fs/f2fs/xattr.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * Portions of this code from linux/fs/ext2/xattr.c
8 *
9 * Copyright (C) 2001-2003 Andreas Gruenbacher <agruen@suse.de>
10 *
11 * Fix by Harrison Xing <harrison@mountainviewdata.com>.
12 * Extended attributes for symlinks and special files added per
13 * suggestion of Luka Renko <luka.renko@hermes.si>.
14 * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>,
15 * Red Hat Inc.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21#include <linux/rwsem.h>
22#include <linux/f2fs_fs.h>
23#include <linux/security.h>
24#include "f2fs.h"
25#include "xattr.h"
26
27static size_t f2fs_xattr_generic_list(struct dentry *dentry, char *list,
Jaegeuk Kimb5614a32014-04-23 12:17:25 +090028 size_t list_size, const char *name, size_t len, int type)
Linus Torvalds8005ecc2012-12-20 13:54:51 -080029{
30 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
31 int total_len, prefix_len = 0;
32 const char *prefix = NULL;
33
34 switch (type) {
35 case F2FS_XATTR_INDEX_USER:
36 if (!test_opt(sbi, XATTR_USER))
37 return -EOPNOTSUPP;
38 prefix = XATTR_USER_PREFIX;
39 prefix_len = XATTR_USER_PREFIX_LEN;
40 break;
41 case F2FS_XATTR_INDEX_TRUSTED:
42 if (!capable(CAP_SYS_ADMIN))
43 return -EPERM;
44 prefix = XATTR_TRUSTED_PREFIX;
45 prefix_len = XATTR_TRUSTED_PREFIX_LEN;
46 break;
47 case F2FS_XATTR_INDEX_SECURITY:
48 prefix = XATTR_SECURITY_PREFIX;
49 prefix_len = XATTR_SECURITY_PREFIX_LEN;
50 break;
51 default:
52 return -EINVAL;
53 }
54
Jaegeuk Kimb5614a32014-04-23 12:17:25 +090055 total_len = prefix_len + len + 1;
Linus Torvalds8005ecc2012-12-20 13:54:51 -080056 if (list && total_len <= list_size) {
57 memcpy(list, prefix, prefix_len);
Jaegeuk Kimb5614a32014-04-23 12:17:25 +090058 memcpy(list + prefix_len, name, len);
59 list[prefix_len + len] = '\0';
Linus Torvalds8005ecc2012-12-20 13:54:51 -080060 }
61 return total_len;
62}
63
64static int f2fs_xattr_generic_get(struct dentry *dentry, const char *name,
65 void *buffer, size_t size, int type)
66{
67 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
68
69 switch (type) {
70 case F2FS_XATTR_INDEX_USER:
71 if (!test_opt(sbi, XATTR_USER))
72 return -EOPNOTSUPP;
73 break;
74 case F2FS_XATTR_INDEX_TRUSTED:
75 if (!capable(CAP_SYS_ADMIN))
76 return -EPERM;
77 break;
78 case F2FS_XATTR_INDEX_SECURITY:
79 break;
80 default:
81 return -EINVAL;
82 }
83 if (strcmp(name, "") == 0)
84 return -EINVAL;
85 return f2fs_getxattr(dentry->d_inode, type, name, buffer, size);
86}
87
88static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name,
89 const void *value, size_t size, int flags, int type)
90{
91 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
92
93 switch (type) {
94 case F2FS_XATTR_INDEX_USER:
95 if (!test_opt(sbi, XATTR_USER))
96 return -EOPNOTSUPP;
97 break;
98 case F2FS_XATTR_INDEX_TRUSTED:
99 if (!capable(CAP_SYS_ADMIN))
100 return -EPERM;
101 break;
102 case F2FS_XATTR_INDEX_SECURITY:
103 break;
104 default:
105 return -EINVAL;
106 }
107 if (strcmp(name, "") == 0)
108 return -EINVAL;
109
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900110 return f2fs_setxattr(dentry->d_inode, type, name,
111 value, size, NULL, flags);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800112}
113
114static size_t f2fs_xattr_advise_list(struct dentry *dentry, char *list,
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900115 size_t list_size, const char *name, size_t len, int type)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800116{
117 const char *xname = F2FS_SYSTEM_ADVISE_PREFIX;
118 size_t size;
119
120 if (type != F2FS_XATTR_INDEX_ADVISE)
121 return 0;
122
123 size = strlen(xname) + 1;
124 if (list && size <= list_size)
125 memcpy(list, xname, size);
126 return size;
127}
128
129static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name,
130 void *buffer, size_t size, int type)
131{
132 struct inode *inode = dentry->d_inode;
133
134 if (strcmp(name, "") != 0)
135 return -EINVAL;
136
137 *((char *)buffer) = F2FS_I(inode)->i_advise;
138 return sizeof(char);
139}
140
141static int f2fs_xattr_advise_set(struct dentry *dentry, const char *name,
142 const void *value, size_t size, int flags, int type)
143{
144 struct inode *inode = dentry->d_inode;
145
146 if (strcmp(name, "") != 0)
147 return -EINVAL;
148 if (!inode_owner_or_capable(inode))
149 return -EPERM;
150 if (value == NULL)
151 return -EINVAL;
152
153 F2FS_I(inode)->i_advise |= *(char *)value;
154 return 0;
155}
156
157#ifdef CONFIG_F2FS_FS_SECURITY
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900158static int __f2fs_setxattr(struct inode *inode, int index,
159 const char *name, const void *value, size_t size,
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900160 struct page *ipage, int);
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900161
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800162static int f2fs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
163 void *page)
164{
165 const struct xattr *xattr;
166 int err = 0;
167
168 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
169 err = __f2fs_setxattr(inode, F2FS_XATTR_INDEX_SECURITY,
170 xattr->name, xattr->value,
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900171 xattr->value_len, (struct page *)page, 0);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800172 if (err < 0)
173 break;
174 }
175 return err;
176}
177
178int f2fs_init_security(struct inode *inode, struct inode *dir,
179 const struct qstr *qstr, struct page *ipage)
180{
181 return security_inode_init_security(inode, dir, qstr,
182 &f2fs_initxattrs, ipage);
183}
184#endif
185
186const struct xattr_handler f2fs_xattr_user_handler = {
187 .prefix = XATTR_USER_PREFIX,
188 .flags = F2FS_XATTR_INDEX_USER,
189 .list = f2fs_xattr_generic_list,
190 .get = f2fs_xattr_generic_get,
191 .set = f2fs_xattr_generic_set,
192};
193
194const struct xattr_handler f2fs_xattr_trusted_handler = {
195 .prefix = XATTR_TRUSTED_PREFIX,
196 .flags = F2FS_XATTR_INDEX_TRUSTED,
197 .list = f2fs_xattr_generic_list,
198 .get = f2fs_xattr_generic_get,
199 .set = f2fs_xattr_generic_set,
200};
201
202const struct xattr_handler f2fs_xattr_advise_handler = {
203 .prefix = F2FS_SYSTEM_ADVISE_PREFIX,
204 .flags = F2FS_XATTR_INDEX_ADVISE,
205 .list = f2fs_xattr_advise_list,
206 .get = f2fs_xattr_advise_get,
207 .set = f2fs_xattr_advise_set,
208};
209
210const struct xattr_handler f2fs_xattr_security_handler = {
211 .prefix = XATTR_SECURITY_PREFIX,
212 .flags = F2FS_XATTR_INDEX_SECURITY,
213 .list = f2fs_xattr_generic_list,
214 .get = f2fs_xattr_generic_get,
215 .set = f2fs_xattr_generic_set,
216};
217
218static const struct xattr_handler *f2fs_xattr_handler_map[] = {
219 [F2FS_XATTR_INDEX_USER] = &f2fs_xattr_user_handler,
220#ifdef CONFIG_F2FS_FS_POSIX_ACL
221 [F2FS_XATTR_INDEX_POSIX_ACL_ACCESS] = &f2fs_xattr_acl_access_handler,
222 [F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &f2fs_xattr_acl_default_handler,
223#endif
224 [F2FS_XATTR_INDEX_TRUSTED] = &f2fs_xattr_trusted_handler,
225#ifdef CONFIG_F2FS_FS_SECURITY
226 [F2FS_XATTR_INDEX_SECURITY] = &f2fs_xattr_security_handler,
227#endif
228 [F2FS_XATTR_INDEX_ADVISE] = &f2fs_xattr_advise_handler,
229};
230
231const struct xattr_handler *f2fs_xattr_handlers[] = {
232 &f2fs_xattr_user_handler,
233#ifdef CONFIG_F2FS_FS_POSIX_ACL
234 &f2fs_xattr_acl_access_handler,
235 &f2fs_xattr_acl_default_handler,
236#endif
237 &f2fs_xattr_trusted_handler,
238#ifdef CONFIG_F2FS_FS_SECURITY
239 &f2fs_xattr_security_handler,
240#endif
241 &f2fs_xattr_advise_handler,
242 NULL,
243};
244
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900245static inline const struct xattr_handler *f2fs_xattr_handler(int index)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800246{
247 const struct xattr_handler *handler = NULL;
248
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900249 if (index > 0 && index < ARRAY_SIZE(f2fs_xattr_handler_map))
250 handler = f2fs_xattr_handler_map[index];
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800251 return handler;
252}
253
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900254static struct f2fs_xattr_entry *__find_xattr(void *base_addr, int index,
255 size_t len, const char *name)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800256{
257 struct f2fs_xattr_entry *entry;
258
259 list_for_each_xattr(entry, base_addr) {
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900260 if (entry->e_name_index != index)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800261 continue;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900262 if (entry->e_name_len != len)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800263 continue;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900264 if (!memcmp(entry->e_name, name, len))
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800265 break;
266 }
267 return entry;
268}
269
270static void *read_all_xattrs(struct inode *inode, struct page *ipage)
271{
272 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
273 struct f2fs_xattr_header *header;
274 size_t size = PAGE_SIZE, inline_size = 0;
275 void *txattr_addr;
276
277 inline_size = inline_xattr_size(inode);
278
Jaegeuk Kim395204b2014-03-20 22:21:08 +0900279 txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800280 if (!txattr_addr)
281 return NULL;
282
283 /* read from inline xattr */
284 if (inline_size) {
285 struct page *page = NULL;
286 void *inline_addr;
287
288 if (ipage) {
289 inline_addr = inline_xattr_addr(ipage);
290 } else {
291 page = get_node_page(sbi, inode->i_ino);
292 if (IS_ERR(page))
293 goto fail;
294 inline_addr = inline_xattr_addr(page);
295 }
296 memcpy(txattr_addr, inline_addr, inline_size);
297 f2fs_put_page(page, 1);
298 }
299
300 /* read from xattr node block */
301 if (F2FS_I(inode)->i_xattr_nid) {
302 struct page *xpage;
303 void *xattr_addr;
304
305 /* The inode already has an extended attribute block. */
306 xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid);
307 if (IS_ERR(xpage))
308 goto fail;
309
310 xattr_addr = page_address(xpage);
311 memcpy(txattr_addr + inline_size, xattr_addr, PAGE_SIZE);
312 f2fs_put_page(xpage, 1);
313 }
314
315 header = XATTR_HDR(txattr_addr);
316
317 /* never been allocated xattrs */
318 if (le32_to_cpu(header->h_magic) != F2FS_XATTR_MAGIC) {
319 header->h_magic = cpu_to_le32(F2FS_XATTR_MAGIC);
320 header->h_refcount = cpu_to_le32(1);
321 }
322 return txattr_addr;
323fail:
324 kzfree(txattr_addr);
325 return NULL;
326}
327
328static inline int write_all_xattrs(struct inode *inode, __u32 hsize,
329 void *txattr_addr, struct page *ipage)
330{
331 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
332 size_t inline_size = 0;
333 void *xattr_addr;
334 struct page *xpage;
335 nid_t new_nid = 0;
336 int err;
337
338 inline_size = inline_xattr_size(inode);
339
340 if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
341 if (!alloc_nid(sbi, &new_nid))
342 return -ENOSPC;
343
344 /* write to inline xattr */
345 if (inline_size) {
346 struct page *page = NULL;
347 void *inline_addr;
348
349 if (ipage) {
350 inline_addr = inline_xattr_addr(ipage);
351 } else {
352 page = get_node_page(sbi, inode->i_ino);
353 if (IS_ERR(page)) {
354 alloc_nid_failed(sbi, new_nid);
355 return PTR_ERR(page);
356 }
357 inline_addr = inline_xattr_addr(page);
358 }
359 memcpy(inline_addr, txattr_addr, inline_size);
360 f2fs_put_page(page, 1);
361
362 /* no need to use xattr node block */
363 if (hsize <= inline_size) {
364 err = truncate_xattr_node(inode, ipage);
365 alloc_nid_failed(sbi, new_nid);
366 return err;
367 }
368 }
369
370 /* write to xattr node block */
371 if (F2FS_I(inode)->i_xattr_nid) {
372 xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid);
373 if (IS_ERR(xpage)) {
374 alloc_nid_failed(sbi, new_nid);
375 return PTR_ERR(xpage);
376 }
377 f2fs_bug_on(new_nid);
378 } else {
379 struct dnode_of_data dn;
380 set_new_dnode(&dn, inode, NULL, NULL, new_nid);
381 xpage = new_node_page(&dn, XATTR_NODE_OFFSET, ipage);
382 if (IS_ERR(xpage)) {
383 alloc_nid_failed(sbi, new_nid);
384 return PTR_ERR(xpage);
385 }
386 alloc_nid_done(sbi, new_nid);
387 }
388
389 xattr_addr = page_address(xpage);
390 memcpy(xattr_addr, txattr_addr + inline_size, PAGE_SIZE -
391 sizeof(struct node_footer));
392 set_page_dirty(xpage);
393 f2fs_put_page(xpage, 1);
394
395 /* need to checkpoint during fsync */
396 F2FS_I(inode)->xattr_ver = cur_cp_version(F2FS_CKPT(sbi));
397 return 0;
398}
399
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900400int f2fs_getxattr(struct inode *inode, int index, const char *name,
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800401 void *buffer, size_t buffer_size)
402{
403 struct f2fs_xattr_entry *entry;
404 void *base_addr;
405 int error = 0;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900406 size_t size, len;
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800407
408 if (name == NULL)
409 return -EINVAL;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900410
411 len = strlen(name);
412 if (len > F2FS_NAME_LEN)
Chao Yu26a9bf52014-03-22 14:59:45 +0800413 return -ERANGE;
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800414
415 base_addr = read_all_xattrs(inode, NULL);
416 if (!base_addr)
417 return -ENOMEM;
418
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900419 entry = __find_xattr(base_addr, index, len, name);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800420 if (IS_XATTR_LAST_ENTRY(entry)) {
421 error = -ENODATA;
422 goto cleanup;
423 }
424
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900425 size = le16_to_cpu(entry->e_value_size);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800426
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900427 if (buffer && size > buffer_size) {
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800428 error = -ERANGE;
429 goto cleanup;
430 }
431
432 if (buffer) {
433 char *pval = entry->e_name + entry->e_name_len;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900434 memcpy(buffer, pval, size);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800435 }
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900436 error = size;
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800437
438cleanup:
439 kzfree(base_addr);
440 return error;
441}
442
443ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
444{
445 struct inode *inode = dentry->d_inode;
446 struct f2fs_xattr_entry *entry;
447 void *base_addr;
448 int error = 0;
449 size_t rest = buffer_size;
450
451 base_addr = read_all_xattrs(inode, NULL);
452 if (!base_addr)
453 return -ENOMEM;
454
455 list_for_each_xattr(entry, base_addr) {
456 const struct xattr_handler *handler =
457 f2fs_xattr_handler(entry->e_name_index);
458 size_t size;
459
460 if (!handler)
461 continue;
462
463 size = handler->list(dentry, buffer, rest, entry->e_name,
464 entry->e_name_len, handler->flags);
465 if (buffer && size > rest) {
466 error = -ERANGE;
467 goto cleanup;
468 }
469
470 if (buffer)
471 buffer += size;
472 rest -= size;
473 }
474 error = buffer_size - rest;
475cleanup:
476 kzfree(base_addr);
477 return error;
478}
479
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900480static int __f2fs_setxattr(struct inode *inode, int index,
481 const char *name, const void *value, size_t size,
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900482 struct page *ipage, int flags)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800483{
484 struct f2fs_inode_info *fi = F2FS_I(inode);
485 struct f2fs_xattr_entry *here, *last;
486 void *base_addr;
487 int found, newsize;
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900488 size_t len;
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800489 __u32 new_hsize;
490 int error = -ENOMEM;
491
492 if (name == NULL)
493 return -EINVAL;
494
495 if (value == NULL)
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900496 size = 0;
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800497
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900498 len = strlen(name);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800499
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900500 if (len > F2FS_NAME_LEN || size > MAX_VALUE_LEN(inode))
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800501 return -ERANGE;
502
503 base_addr = read_all_xattrs(inode, ipage);
504 if (!base_addr)
505 goto exit;
506
507 /* find entry with wanted name. */
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900508 here = __find_xattr(base_addr, index, len, name);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800509
510 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1;
511 last = here;
512
513 while (!IS_XATTR_LAST_ENTRY(last))
514 last = XATTR_NEXT_ENTRY(last);
515
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900516 newsize = XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + len + size);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800517
518 /* 1. Check space */
519 if (value) {
520 int free;
521 /*
522 * If value is NULL, it is remove operation.
523 * In case of update operation, we caculate free.
524 */
525 free = MIN_OFFSET(inode) - ((char *)last - (char *)base_addr);
526 if (found)
527 free = free + ENTRY_SIZE(here);
528
Changman Leeb1a94e82013-11-15 10:42:51 +0900529 if (unlikely(free < newsize)) {
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800530 error = -ENOSPC;
531 goto exit;
532 }
533 }
534
535 /* 2. Remove old entry */
536 if (found) {
537 /*
538 * If entry is found, remove old entry.
539 * If not found, remove operation is not needed.
540 */
541 struct f2fs_xattr_entry *next = XATTR_NEXT_ENTRY(here);
542 int oldsize = ENTRY_SIZE(here);
543
544 memmove(here, next, (char *)last - (char *)next);
545 last = (struct f2fs_xattr_entry *)((char *)last - oldsize);
546 memset(last, 0, oldsize);
547 }
548
549 new_hsize = (char *)last - (char *)base_addr;
550
551 /* 3. Write new entry */
552 if (value) {
553 char *pval;
554 /*
555 * Before we come here, old entry is removed.
556 * We just write new entry.
557 */
558 memset(last, 0, newsize);
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900559 last->e_name_index = index;
560 last->e_name_len = len;
561 memcpy(last->e_name, name, len);
562 pval = last->e_name + len;
563 memcpy(pval, value, size);
564 last->e_value_size = cpu_to_le16(size);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800565 new_hsize += newsize;
566 }
567
568 error = write_all_xattrs(inode, new_hsize, base_addr, ipage);
569 if (error)
570 goto exit;
571
572 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
573 inode->i_mode = fi->i_acl_mode;
574 inode->i_ctime = CURRENT_TIME;
575 clear_inode_flag(fi, FI_ACL_MODE);
576 }
577
578 if (ipage)
579 update_inode(inode, ipage);
580 else
581 update_inode_page(inode);
582exit:
583 kzfree(base_addr);
584 return error;
585}
586
Jaegeuk Kimb5614a32014-04-23 12:17:25 +0900587int f2fs_setxattr(struct inode *inode, int index, const char *name,
588 const void *value, size_t size,
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900589 struct page *ipage, int flags)
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800590{
591 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
592 int err;
593
594 f2fs_balance_fs(sbi);
595
596 f2fs_lock_op(sbi);
Jaegeuk Kimee722542014-03-20 19:10:08 +0900597 /* protect xattr_ver */
598 down_write(&F2FS_I(inode)->i_sem);
Jaegeuk Kim2eb8e7c2014-04-23 12:23:14 +0900599 err = __f2fs_setxattr(inode, index, name, value, size, ipage, flags);
Jaegeuk Kimee722542014-03-20 19:10:08 +0900600 up_write(&F2FS_I(inode)->i_sem);
Linus Torvalds8005ecc2012-12-20 13:54:51 -0800601 f2fs_unlock_op(sbi);
602
603 return err;
604}