[GFS2] [-mm patch] fs/gfs2/: possible cleanups
[powerpc.git] / fs / gfs2 / ondisk.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License v.2.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <asm/semaphore.h>
16
17 #include "gfs2.h"
18 #include <linux/gfs2_ondisk.h>
19
20 #define pv(struct, member, fmt) printk(KERN_INFO "  "#member" = "fmt"\n", \
21                                        struct->member);
22 #define pa(struct, member, count) print_array(#member, struct->member, count);
23
24 /**
25  * print_array - Print out an array of bytes
26  * @title: what to print before the array
27  * @buf: the array
28  * @count: the number of bytes
29  *
30  */
31 #if 0
32 static void print_array(char *title, char *buf, int count)
33 {
34         int x;
35
36         printk(KERN_INFO "  %s =\n" KERN_INFO, title);
37         for (x = 0; x < count; x++) {
38                 printk("%.2X ", (unsigned char)buf[x]);
39                 if (x % 16 == 15)
40                         printk("\n" KERN_INFO);
41         }
42         if (x % 16)
43                 printk("\n");
44 }
45 #endif  /*  0  */
46
47 /*
48  * gfs2_xxx_in - read in an xxx struct
49  * first arg: the cpu-order structure
50  * buf: the disk-order buffer
51  *
52  * gfs2_xxx_out - write out an xxx struct
53  * first arg: the cpu-order structure
54  * buf: the disk-order buffer
55  *
56  * gfs2_xxx_print - print out an xxx struct
57  * first arg: the cpu-order structure
58  */
59
60 void gfs2_inum_in(struct gfs2_inum *no, char *buf)
61 {
62         struct gfs2_inum *str = (struct gfs2_inum *)buf;
63
64         no->no_formal_ino = be64_to_cpu(str->no_formal_ino);
65         no->no_addr = be64_to_cpu(str->no_addr);
66 }
67
68 void gfs2_inum_out(const struct gfs2_inum *no, char *buf)
69 {
70         struct gfs2_inum *str = (struct gfs2_inum *)buf;
71
72         str->no_formal_ino = cpu_to_be64(no->no_formal_ino);
73         str->no_addr = cpu_to_be64(no->no_addr);
74 }
75
76 static void gfs2_inum_print(struct gfs2_inum *no)
77 {
78         pv(no, no_formal_ino, "%llu");
79         pv(no, no_addr, "%llu");
80 }
81
82 static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf)
83 {
84         struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;
85
86         mh->mh_magic = be32_to_cpu(str->mh_magic);
87         mh->mh_type = be32_to_cpu(str->mh_type);
88         mh->mh_format = be32_to_cpu(str->mh_format);
89 }
90
91 static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf)
92 {
93         struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;
94
95         str->mh_magic = cpu_to_be32(mh->mh_magic);
96         str->mh_type = cpu_to_be32(mh->mh_type);
97         str->mh_format = cpu_to_be32(mh->mh_format);
98 }
99
100 static void gfs2_meta_header_print(struct gfs2_meta_header *mh)
101 {
102         pv(mh, mh_magic, "0x%.8X");
103         pv(mh, mh_type, "%u");
104         pv(mh, mh_format, "%u");
105 }
106
107 void gfs2_sb_in(struct gfs2_sb *sb, char *buf)
108 {
109         struct gfs2_sb *str = (struct gfs2_sb *)buf;
110
111         gfs2_meta_header_in(&sb->sb_header, buf);
112
113         sb->sb_fs_format = be32_to_cpu(str->sb_fs_format);
114         sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format);
115         sb->sb_bsize = be32_to_cpu(str->sb_bsize);
116         sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift);
117
118         gfs2_inum_in(&sb->sb_master_dir, (char *)&str->sb_master_dir);
119         gfs2_inum_in(&sb->sb_root_dir, (char *)&str->sb_root_dir);
120
121         memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
122         memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
123 }
124
125 #if 0
126 void gfs2_sb_print(struct gfs2_sb *sb)
127 {
128         gfs2_meta_header_print(&sb->sb_header);
129
130         pv(sb, sb_fs_format, "%u");
131         pv(sb, sb_multihost_format, "%u");
132
133         pv(sb, sb_bsize, "%u");
134         pv(sb, sb_bsize_shift, "%u");
135
136         gfs2_inum_print(&sb->sb_master_dir);
137
138         pv(sb, sb_lockproto, "%s");
139         pv(sb, sb_locktable, "%s");
140 }
141 #endif  /*  0  */
142
143 void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf)
144 {
145         struct gfs2_rindex *str = (struct gfs2_rindex *)buf;
146
147         ri->ri_addr = be64_to_cpu(str->ri_addr);
148         ri->ri_length = be32_to_cpu(str->ri_length);
149         ri->ri_data0 = be64_to_cpu(str->ri_data0);
150         ri->ri_data = be32_to_cpu(str->ri_data);
151         ri->ri_bitbytes = be32_to_cpu(str->ri_bitbytes);
152
153 }
154
155 #if 0
156 void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf)
157 {
158         struct gfs2_rindex *str = (struct gfs2_rindex *)buf;
159
160         str->ri_addr = cpu_to_be64(ri->ri_addr);
161         str->ri_length = cpu_to_be32(ri->ri_length);
162         str->__pad = 0;
163
164         str->ri_data0 = cpu_to_be64(ri->ri_data0);
165         str->ri_data = cpu_to_be32(ri->ri_data);
166         str->ri_bitbytes = cpu_to_be32(ri->ri_bitbytes);
167         memset(str->ri_reserved, 0, sizeof(str->ri_reserved));
168 }
169
170 #endif  /*  0  */
171
172 void gfs2_rindex_print(struct gfs2_rindex *ri)
173 {
174         pv(ri, ri_addr, "%llu");
175         pv(ri, ri_length, "%u");
176
177         pv(ri, ri_data0, "%llu");
178         pv(ri, ri_data, "%u");
179
180         pv(ri, ri_bitbytes, "%u");
181 }
182
183 void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf)
184 {
185         struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf;
186
187         gfs2_meta_header_in(&rg->rg_header, buf);
188         rg->rg_flags = be32_to_cpu(str->rg_flags);
189         rg->rg_free = be32_to_cpu(str->rg_free);
190         rg->rg_dinodes = be32_to_cpu(str->rg_dinodes);
191 }
192
193 void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf)
194 {
195         struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf;
196
197         gfs2_meta_header_out(&rg->rg_header, buf);
198         str->rg_flags = cpu_to_be32(rg->rg_flags);
199         str->rg_free = cpu_to_be32(rg->rg_free);
200         str->rg_dinodes = cpu_to_be32(rg->rg_dinodes);
201
202         memset(&str->rg_reserved, 0, sizeof(str->rg_reserved));
203 }
204
205 #if 0
206 void gfs2_rgrp_print(struct gfs2_rgrp *rg)
207 {
208         gfs2_meta_header_print(&rg->rg_header);
209         pv(rg, rg_flags, "%u");
210         pv(rg, rg_free, "%u");
211         pv(rg, rg_dinodes, "%u");
212
213         pa(rg, rg_reserved, 36);
214 }
215 #endif  /*  0  */
216
217 void gfs2_quota_in(struct gfs2_quota *qu, char *buf)
218 {
219         struct gfs2_quota *str = (struct gfs2_quota *)buf;
220
221         qu->qu_limit = be64_to_cpu(str->qu_limit);
222         qu->qu_warn = be64_to_cpu(str->qu_warn);
223         qu->qu_value = be64_to_cpu(str->qu_value);
224 }
225
226 #if 0
227
228 void gfs2_quota_out(struct gfs2_quota *qu, char *buf)
229 {
230         struct gfs2_quota *str = (struct gfs2_quota *)buf;
231
232         str->qu_limit = cpu_to_be64(qu->qu_limit);
233         str->qu_warn = cpu_to_be64(qu->qu_warn);
234         str->qu_value = cpu_to_be64(qu->qu_value);
235 }
236
237 void gfs2_quota_print(struct gfs2_quota *qu)
238 {
239         pv(qu, qu_limit, "%llu");
240         pv(qu, qu_warn, "%llu");
241         pv(qu, qu_value, "%lld");
242 }
243
244 #endif  /*  0  */
245
246 void gfs2_dinode_in(struct gfs2_dinode *di, char *buf)
247 {
248         struct gfs2_dinode *str = (struct gfs2_dinode *)buf;
249
250         gfs2_meta_header_in(&di->di_header, buf);
251         gfs2_inum_in(&di->di_num, (char *)&str->di_num);
252
253         di->di_mode = be32_to_cpu(str->di_mode);
254         di->di_uid = be32_to_cpu(str->di_uid);
255         di->di_gid = be32_to_cpu(str->di_gid);
256         di->di_nlink = be32_to_cpu(str->di_nlink);
257         di->di_size = be64_to_cpu(str->di_size);
258         di->di_blocks = be64_to_cpu(str->di_blocks);
259         di->di_atime = be64_to_cpu(str->di_atime);
260         di->di_mtime = be64_to_cpu(str->di_mtime);
261         di->di_ctime = be64_to_cpu(str->di_ctime);
262         di->di_major = be32_to_cpu(str->di_major);
263         di->di_minor = be32_to_cpu(str->di_minor);
264
265         di->di_goal_meta = be64_to_cpu(str->di_goal_meta);
266         di->di_goal_data = be64_to_cpu(str->di_goal_data);
267
268         di->di_flags = be32_to_cpu(str->di_flags);
269         di->di_payload_format = be32_to_cpu(str->di_payload_format);
270         di->di_height = be16_to_cpu(str->di_height);
271
272         di->di_depth = be16_to_cpu(str->di_depth);
273         di->di_entries = be32_to_cpu(str->di_entries);
274
275         di->di_eattr = be64_to_cpu(str->di_eattr);
276
277 }
278
279 void gfs2_dinode_out(struct gfs2_dinode *di, char *buf)
280 {
281         struct gfs2_dinode *str = (struct gfs2_dinode *)buf;
282
283         gfs2_meta_header_out(&di->di_header, buf);
284         gfs2_inum_out(&di->di_num, (char *)&str->di_num);
285
286         str->di_mode = cpu_to_be32(di->di_mode);
287         str->di_uid = cpu_to_be32(di->di_uid);
288         str->di_gid = cpu_to_be32(di->di_gid);
289         str->di_nlink = cpu_to_be32(di->di_nlink);
290         str->di_size = cpu_to_be64(di->di_size);
291         str->di_blocks = cpu_to_be64(di->di_blocks);
292         str->di_atime = cpu_to_be64(di->di_atime);
293         str->di_mtime = cpu_to_be64(di->di_mtime);
294         str->di_ctime = cpu_to_be64(di->di_ctime);
295         str->di_major = cpu_to_be32(di->di_major);
296         str->di_minor = cpu_to_be32(di->di_minor);
297
298         str->di_goal_meta = cpu_to_be64(di->di_goal_meta);
299         str->di_goal_data = cpu_to_be64(di->di_goal_data);
300
301         str->di_flags = cpu_to_be32(di->di_flags);
302         str->di_payload_format = cpu_to_be32(di->di_payload_format);
303         str->di_height = cpu_to_be16(di->di_height);
304
305         str->di_depth = cpu_to_be16(di->di_depth);
306         str->di_entries = cpu_to_be32(di->di_entries);
307
308         str->di_eattr = cpu_to_be64(di->di_eattr);
309
310 }
311
312 void gfs2_dinode_print(struct gfs2_dinode *di)
313 {
314         gfs2_meta_header_print(&di->di_header);
315         gfs2_inum_print(&di->di_num);
316
317         pv(di, di_mode, "0%o");
318         pv(di, di_uid, "%u");
319         pv(di, di_gid, "%u");
320         pv(di, di_nlink, "%u");
321         pv(di, di_size, "%llu");
322         pv(di, di_blocks, "%llu");
323         pv(di, di_atime, "%lld");
324         pv(di, di_mtime, "%lld");
325         pv(di, di_ctime, "%lld");
326         pv(di, di_major, "%u");
327         pv(di, di_minor, "%u");
328
329         pv(di, di_goal_meta, "%llu");
330         pv(di, di_goal_data, "%llu");
331
332         pv(di, di_flags, "0x%.8X");
333         pv(di, di_payload_format, "%u");
334         pv(di, di_height, "%u");
335
336         pv(di, di_depth, "%u");
337         pv(di, di_entries, "%u");
338
339         pv(di, di_eattr, "%llu");
340 }
341
342 #if 0
343
344 void gfs2_dirent_print(struct gfs2_dirent *de, char *name)
345 {
346         char buf[GFS2_FNAMESIZE + 1];
347
348         gfs2_inum_print(&de->de_inum);
349         pv(de, de_hash, "0x%.8X");
350         pv(de, de_rec_len, "%u");
351         pv(de, de_name_len, "%u");
352         pv(de, de_type, "%u");
353
354         memset(buf, 0, GFS2_FNAMESIZE + 1);
355         memcpy(buf, name, de->de_name_len);
356         printk(KERN_INFO "  name = %s\n", buf);
357 }
358
359 void gfs2_leaf_print(struct gfs2_leaf *lf)
360 {
361         gfs2_meta_header_print(&lf->lf_header);
362         pv(lf, lf_depth, "%u");
363         pv(lf, lf_entries, "%u");
364         pv(lf, lf_dirent_format, "%u");
365         pv(lf, lf_next, "%llu");
366
367         pa(lf, lf_reserved, 32);
368 }
369
370 void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf)
371 {
372         struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf;
373
374         ea->ea_rec_len = be32_to_cpu(str->ea_rec_len);
375         ea->ea_data_len = be32_to_cpu(str->ea_data_len);
376         ea->ea_name_len = str->ea_name_len;
377         ea->ea_type = str->ea_type;
378         ea->ea_flags = str->ea_flags;
379         ea->ea_num_ptrs = str->ea_num_ptrs;
380 }
381
382 void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf)
383 {
384         struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf;
385
386         str->ea_rec_len = cpu_to_be32(ea->ea_rec_len);
387         str->ea_data_len = cpu_to_be32(ea->ea_data_len);
388         str->ea_name_len = ea->ea_name_len;
389         str->ea_type = ea->ea_type;
390         str->ea_flags = ea->ea_flags;
391         str->ea_num_ptrs = ea->ea_num_ptrs;
392         str->__pad = 0;
393 }
394
395 void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name)
396 {
397         char buf[GFS2_EA_MAX_NAME_LEN + 1];
398
399         pv(ea, ea_rec_len, "%u");
400         pv(ea, ea_data_len, "%u");
401         pv(ea, ea_name_len, "%u");
402         pv(ea, ea_type, "%u");
403         pv(ea, ea_flags, "%u");
404         pv(ea, ea_num_ptrs, "%u");
405
406         memset(buf, 0, GFS2_EA_MAX_NAME_LEN + 1);
407         memcpy(buf, name, ea->ea_name_len);
408         printk(KERN_INFO "  name = %s\n", buf);
409 }
410
411 #endif  /*  0  */
412
413 void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf)
414 {
415         struct gfs2_log_header *str = (struct gfs2_log_header *)buf;
416
417         gfs2_meta_header_in(&lh->lh_header, buf);
418         lh->lh_sequence = be64_to_cpu(str->lh_sequence);
419         lh->lh_flags = be32_to_cpu(str->lh_flags);
420         lh->lh_tail = be32_to_cpu(str->lh_tail);
421         lh->lh_blkno = be32_to_cpu(str->lh_blkno);
422         lh->lh_hash = be32_to_cpu(str->lh_hash);
423 }
424
425 #if 0
426
427 void gfs2_log_header_print(struct gfs2_log_header *lh)
428 {
429         gfs2_meta_header_print(&lh->lh_header);
430         pv(lh, lh_sequence, "%llu");
431         pv(lh, lh_flags, "0x%.8X");
432         pv(lh, lh_tail, "%u");
433         pv(lh, lh_blkno, "%u");
434         pv(lh, lh_hash, "0x%.8X");
435 }
436
437 void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld)
438 {
439         gfs2_meta_header_print(&ld->ld_header);
440         pv(ld, ld_type, "%u");
441         pv(ld, ld_length, "%u");
442         pv(ld, ld_data1, "%u");
443         pv(ld, ld_data2, "%u");
444
445         pa(ld, ld_reserved, 32);
446 }
447
448 #endif  /*  0  */
449
450 void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf)
451 {
452         struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf;
453
454         ir->ir_start = be64_to_cpu(str->ir_start);
455         ir->ir_length = be64_to_cpu(str->ir_length);
456 }
457
458 void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf)
459 {
460         struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf;
461
462         str->ir_start = cpu_to_be64(ir->ir_start);
463         str->ir_length = cpu_to_be64(ir->ir_length);
464 }
465
466 #if 0
467 void gfs2_inum_range_print(struct gfs2_inum_range *ir)
468 {
469         pv(ir, ir_start, "%llu");
470         pv(ir, ir_length, "%llu");
471 }
472 #endif  /*  0  */
473
474 void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf)
475 {
476         struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf;
477
478         sc->sc_total = be64_to_cpu(str->sc_total);
479         sc->sc_free = be64_to_cpu(str->sc_free);
480         sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
481 }
482
483 void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf)
484 {
485         struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf;
486
487         str->sc_total = cpu_to_be64(sc->sc_total);
488         str->sc_free = cpu_to_be64(sc->sc_free);
489         str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
490 }
491
492 #if 0
493 void gfs2_statfs_change_print(struct gfs2_statfs_change *sc)
494 {
495         pv(sc, sc_total, "%lld");
496         pv(sc, sc_free, "%lld");
497         pv(sc, sc_dinodes, "%lld");
498 }
499 #endif  /*  0  */
500
501 void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf)
502 {
503         struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf;
504
505         gfs2_inum_in(&ut->ut_inum, buf);
506         ut->ut_flags = be32_to_cpu(str->ut_flags);
507 }
508
509 void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf)
510 {
511         struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf;
512
513         gfs2_inum_out(&ut->ut_inum, buf);
514         str->ut_flags = cpu_to_be32(ut->ut_flags);
515         str->__pad = 0;
516 }
517
518 #if 0
519
520 void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut)
521 {
522         gfs2_inum_print(&ut->ut_inum);
523         pv(ut, ut_flags, "%u");
524 }
525
526 #endif  /*  0  */
527
528 void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf)
529 {
530         struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf;
531
532         qc->qc_change = be64_to_cpu(str->qc_change);
533         qc->qc_flags = be32_to_cpu(str->qc_flags);
534         qc->qc_id = be32_to_cpu(str->qc_id);
535 }
536
537 #if 0
538
539 void gfs2_quota_change_print(struct gfs2_quota_change *qc)
540 {
541         pv(qc, qc_change, "%lld");
542         pv(qc, qc_flags, "0x%.8X");
543         pv(qc, qc_id, "%u");
544 }
545
546 #endif  /*  0  */
547