aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk.kim@samsung.com>2013-08-12 21:13:55 -0400
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2013-08-26 07:15:06 -0400
commitdd9cfe236f95bbda9ceb5a4ca419b9fb574c95f9 (patch)
tree3b0c9bd1cea176d45492cdea3ba2dab20e703ecf /fs
parentde93653fe31fc9439971296842dcd0280f8ab5f4 (diff)
f2fs: introduce __find_xattr for readability
The __find_xattr is to search the wanted xattr entry starting from the base_addr. If not found, the returned entry is the last empty xattr entry that can be allocated newly. Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/f2fs/xattr.c46
-rw-r--r--fs/f2fs/xattr.h3
2 files changed, 22 insertions, 27 deletions
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index 3bc307c22b70..45a8ef882f89 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -246,6 +246,22 @@ static inline const struct xattr_handler *f2fs_xattr_handler(int name_index)
246 return handler; 246 return handler;
247} 247}
248 248
249static struct f2fs_xattr_entry *__find_xattr(void *base_addr, int name_index,
250 size_t name_len, const char *name)
251{
252 struct f2fs_xattr_entry *entry;
253
254 list_for_each_xattr(entry, base_addr) {
255 if (entry->e_name_index != name_index)
256 continue;
257 if (entry->e_name_len != name_len)
258 continue;
259 if (!memcmp(entry->e_name, name, name_len))
260 break;
261 }
262 return entry;
263}
264
249int f2fs_getxattr(struct inode *inode, int name_index, const char *name, 265int f2fs_getxattr(struct inode *inode, int name_index, const char *name,
250 void *buffer, size_t buffer_size) 266 void *buffer, size_t buffer_size)
251{ 267{
@@ -253,8 +269,7 @@ int f2fs_getxattr(struct inode *inode, int name_index, const char *name,
253 struct f2fs_inode_info *fi = F2FS_I(inode); 269 struct f2fs_inode_info *fi = F2FS_I(inode);
254 struct f2fs_xattr_entry *entry; 270 struct f2fs_xattr_entry *entry;
255 struct page *page; 271 struct page *page;
256 void *base_addr; 272 int error = 0;
257 int error = 0, found = 0;
258 size_t value_len, name_len; 273 size_t value_len, name_len;
259 274
260 if (name == NULL) 275 if (name == NULL)
@@ -267,19 +282,9 @@ int f2fs_getxattr(struct inode *inode, int name_index, const char *name,
267 page = get_node_page(sbi, fi->i_xattr_nid); 282 page = get_node_page(sbi, fi->i_xattr_nid);
268 if (IS_ERR(page)) 283 if (IS_ERR(page))
269 return PTR_ERR(page); 284 return PTR_ERR(page);
270 base_addr = page_address(page);
271 285
272 list_for_each_xattr(entry, base_addr) { 286 entry = __find_xattr(page_address(page), name_index, name_len, name);
273 if (entry->e_name_index != name_index) 287 if (IS_XATTR_LAST_ENTRY(entry)) {
274 continue;
275 if (entry->e_name_len != name_len)
276 continue;
277 if (!memcmp(entry->e_name, name, name_len)) {
278 found = 1;
279 break;
280 }
281 }
282 if (!found) {
283 error = -ENODATA; 288 error = -ENODATA;
284 goto cleanup; 289 goto cleanup;
285 } 290 }
@@ -417,18 +422,9 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
417 } 422 }
418 423
419 /* find entry with wanted name. */ 424 /* find entry with wanted name. */
420 found = 0; 425 here = __find_xattr(base_addr, name_index, name_len, name);
421 list_for_each_xattr(here, base_addr) {
422 if (here->e_name_index != name_index)
423 continue;
424 if (here->e_name_len != name_len)
425 continue;
426 if (!memcmp(here->e_name, name, name_len)) {
427 found = 1;
428 break;
429 }
430 }
431 426
427 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1;
432 last = here; 428 last = here;
433 429
434 while (!IS_XATTR_LAST_ENTRY(last)) 430 while (!IS_XATTR_LAST_ENTRY(last))
diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
index 3c0817bef25d..c3ec042707d4 100644
--- a/fs/f2fs/xattr.h
+++ b/fs/f2fs/xattr.h
@@ -51,7 +51,7 @@ struct f2fs_xattr_entry {
51 51
52#define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr)) 52#define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
53#define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr)) 53#define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
54#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr)+1)) 54#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
55#define XATTR_ROUND (3) 55#define XATTR_ROUND (3)
56 56
57#define XATTR_ALIGN(size) ((size + XATTR_ROUND) & ~XATTR_ROUND) 57#define XATTR_ALIGN(size) ((size + XATTR_ROUND) & ~XATTR_ROUND)
@@ -69,7 +69,6 @@ struct f2fs_xattr_entry {
69 !IS_XATTR_LAST_ENTRY(entry);\ 69 !IS_XATTR_LAST_ENTRY(entry);\
70 entry = XATTR_NEXT_ENTRY(entry)) 70 entry = XATTR_NEXT_ENTRY(entry))
71 71
72
73#define MIN_OFFSET XATTR_ALIGN(PAGE_SIZE - \ 72#define MIN_OFFSET XATTR_ALIGN(PAGE_SIZE - \
74 sizeof(struct node_footer) - \ 73 sizeof(struct node_footer) - \
75 sizeof(__u32)) 74 sizeof(__u32))