aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/Makefile2
-rw-r--r--fs/btrfs/ctree.c1
-rw-r--r--fs/btrfs/ctree.h74
-rw-r--r--fs/btrfs/extent-tree.c2
-rw-r--r--fs/btrfs/struct-funcs.c97
-rw-r--r--fs/btrfs/tree-defrag.c2
6 files changed, 104 insertions, 74 deletions
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index a3b51085d7f0..551743be5f03 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -5,7 +5,7 @@ obj-m := btrfs.o
5btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ 5btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
6 hash.o file-item.o inode-item.o inode-map.o disk-io.o \ 6 hash.o file-item.o inode-item.o inode-map.o disk-io.o \
7 transaction.o bit-radix.o inode.o file.o tree-defrag.o \ 7 transaction.o bit-radix.o inode.o file.o tree-defrag.o \
8 extent_map.o sysfs.o 8 extent_map.o sysfs.o struct-funcs.o
9 9
10#btrfs-y := ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ 10#btrfs-y := ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
11# root-tree.o dir-item.o hash.o file-item.o inode-item.o \ 11# root-tree.o dir-item.o hash.o file-item.o inode-item.o \
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 54a5d006c562..0c6ed17ac1bc 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -16,7 +16,6 @@
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19#include <linux/highmem.h>
20#include "ctree.h" 19#include "ctree.h"
21#include "disk-io.h" 20#include "disk-io.h"
22#include "transaction.h" 21#include "transaction.h"
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a942a2427228..d1c6f023a302 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -426,77 +426,11 @@ struct btrfs_root {
426 offsetof(type, member), \ 426 offsetof(type, member), \
427 sizeof(((type *)0)->member))) 427 sizeof(((type *)0)->member)))
428 428
429#ifndef BTRFS_SETGET_FUNCS
429#define BTRFS_SETGET_FUNCS(name, type, member, bits) \ 430#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
430static inline u##bits btrfs_##name(struct extent_buffer *eb, \ 431u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
431 type *s) \ 432void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
432{ \ 433#endif
433 int err; \
434 char *map_token; \
435 char *kaddr; \
436 int unmap_on_exit = (eb->map_token == NULL); \
437 unsigned long map_start; \
438 unsigned long map_len; \
439 unsigned long offset = (unsigned long)s + \
440 offsetof(type, member); \
441 if (eb->map_token && offset >= eb->map_start && \
442 offset + sizeof(((type *)0)->member) <= eb->map_start + \
443 eb->map_len) { \
444 kaddr = eb->kaddr; \
445 map_start = eb->map_start; \
446 err = 0; \
447 } else { \
448 err = map_extent_buffer(eb, offset, \
449 sizeof(((type *)0)->member), \
450 &map_token, &kaddr, \
451 &map_start, &map_len, KM_USER1); \
452 } \
453 if (!err) { \
454 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
455 map_start); \
456 u##bits res = le##bits##_to_cpu(*tmp); \
457 if (unmap_on_exit) \
458 unmap_extent_buffer(eb, map_token, KM_USER1); \
459 return res; \
460 } else { \
461 __le##bits res; \
462 read_eb_member(eb, s, type, member, &res); \
463 return le##bits##_to_cpu(res); \
464 } \
465} \
466static inline void btrfs_set_##name(struct extent_buffer *eb, \
467 type *s, u##bits val) \
468{ \
469 int err; \
470 char *map_token; \
471 char *kaddr; \
472 unsigned long map_start; \
473 unsigned long map_len; \
474 int unmap_on_exit = (eb->map_token == NULL); \
475 unsigned long offset = (unsigned long)s + \
476 offsetof(type, member); \
477 if (eb->map_token && offset >= eb->map_start && \
478 offset + sizeof(((type *)0)->member) <= eb->map_start + \
479 eb->map_len) { \
480 kaddr = eb->kaddr; \
481 map_start = eb->map_start; \
482 err = 0; \
483 } else { \
484 err = map_extent_buffer(eb, offset, \
485 sizeof(((type *)0)->member), \
486 &map_token, &kaddr, \
487 &map_start, &map_len, KM_USER1); \
488 } \
489 if (!err) { \
490 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
491 map_start); \
492 *tmp = cpu_to_le##bits(val); \
493 if (unmap_on_exit) \
494 unmap_extent_buffer(eb, map_token, KM_USER1); \
495 } else { \
496 val = cpu_to_le##bits(val); \
497 write_eb_member(eb, s, type, member, &val); \
498 } \
499}
500 434
501#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ 435#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
502static inline u##bits btrfs_##name(struct extent_buffer *eb) \ 436static inline u##bits btrfs_##name(struct extent_buffer *eb) \
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 525fa845d613..e4e68ea96483 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1443,7 +1443,7 @@ int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1443 for (i = 0; i <= orig_level; i++) { 1443 for (i = 0; i <= orig_level; i++) {
1444 if (path->nodes[i]) { 1444 if (path->nodes[i]) {
1445 free_extent_buffer(path->nodes[i]); 1445 free_extent_buffer(path->nodes[i]);
1446 path->nodes[i] = 0; 1446 path->nodes[i] = NULL;
1447 } 1447 }
1448 } 1448 }
1449out: 1449out:
diff --git a/fs/btrfs/struct-funcs.c b/fs/btrfs/struct-funcs.c
new file mode 100644
index 000000000000..cf68fcf9b552
--- /dev/null
+++ b/fs/btrfs/struct-funcs.c
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
17 */
18
19#include <linux/highmem.h>
20#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
21u##bits btrfs_##name(struct extent_buffer *eb, \
22 type *s) \
23{ \
24 unsigned long offset = (unsigned long)s + \
25 offsetof(type, member); \
26 __le##bits *tmp; \
27 /* ugly, but we want the fast path here */ \
28 if (eb->map_token && offset >= eb->map_start && \
29 offset + sizeof(((type *)0)->member) <= eb->map_start + \
30 eb->map_len) { \
31 tmp = (__le##bits *)(eb->kaddr + offset - \
32 eb->map_start); \
33 return le##bits##_to_cpu(*tmp); \
34 } \
35 { \
36 int err; \
37 char *map_token; \
38 char *kaddr; \
39 int unmap_on_exit = (eb->map_token == NULL); \
40 unsigned long map_start; \
41 unsigned long map_len; \
42 __le##bits res; \
43 err = map_extent_buffer(eb, offset, \
44 sizeof(((type *)0)->member), \
45 &map_token, &kaddr, \
46 &map_start, &map_len, KM_USER1); \
47 if (err) { \
48 read_eb_member(eb, s, type, member, &res); \
49 return le##bits##_to_cpu(res); \
50 } \
51 tmp = (__le##bits *)(kaddr + offset - map_start); \
52 res = le##bits##_to_cpu(*tmp); \
53 if (unmap_on_exit) \
54 unmap_extent_buffer(eb, map_token, KM_USER1); \
55 return res; \
56 } \
57} \
58void btrfs_set_##name(struct extent_buffer *eb, \
59 type *s, u##bits val) \
60{ \
61 unsigned long offset = (unsigned long)s + \
62 offsetof(type, member); \
63 __le##bits *tmp; \
64 /* ugly, but we want the fast path here */ \
65 if (eb->map_token && offset >= eb->map_start && \
66 offset + sizeof(((type *)0)->member) <= eb->map_start + \
67 eb->map_len) { \
68 tmp = (__le##bits *)(eb->kaddr + offset - \
69 eb->map_start); \
70 *tmp = cpu_to_le##bits(val); \
71 return; \
72 } \
73 { \
74 int err; \
75 char *map_token; \
76 char *kaddr; \
77 int unmap_on_exit = (eb->map_token == NULL); \
78 unsigned long map_start; \
79 unsigned long map_len; \
80 err = map_extent_buffer(eb, offset, \
81 sizeof(((type *)0)->member), \
82 &map_token, &kaddr, \
83 &map_start, &map_len, KM_USER1); \
84 if (err) { \
85 val = cpu_to_le##bits(val); \
86 write_eb_member(eb, s, type, member, &val); \
87 return; \
88 } \
89 tmp = (__le##bits *)(kaddr + offset - map_start); \
90 *tmp = cpu_to_le##bits(val); \
91 if (unmap_on_exit) \
92 unmap_extent_buffer(eb, map_token, KM_USER1); \
93 } \
94}
95
96#include "ctree.h"
97
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index d23216aa4ab5..0d1a1be0995c 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -239,7 +239,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
239 for (i = 0; i <= orig_level; i++) { 239 for (i = 0; i <= orig_level; i++) {
240 if (path->nodes[i]) { 240 if (path->nodes[i]) {
241 free_extent_buffer(path->nodes[i]); 241 free_extent_buffer(path->nodes[i]);
242 path->nodes[i] = 0; 242 path->nodes[i] = NULL;
243 } 243 }
244 } 244 }
245out: 245out: