GFS2: dentry, export, super and vm operations
PATCH 6/16 GFS2: dentry, export, super and vm operations
[PATCH 06/16] GFS2: dentry, export, super and vm operations
The GFS2 dentry interface, NFS operations, superblock operations, VM operaions, transaction code, unlinked inode code and GFS2 utility routines.
fs/gfs2/ops_dentry.c | 123 ++++++ fs/gfs2/ops_dentry.h | 15 fs/gfs2/ops_export.c | 293 +++++++++++++++ fs/gfs2/ops_export.h | 19 fs/gfs2/ops_super.c | 472 ++++++++++++++++++++++++ fs/gfs2/ops_super.h | 15 fs/gfs2/ops_vm.c | 188 +++++++++ fs/gfs2/ops_vm.h | 16 fs/gfs2/super.c | 979 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/gfs2/super.h | 52 ++ fs/gfs2/trans.c | 184 +++++++++ fs/gfs2/trans.h | 34 + fs/gfs2/util.c | 245 ++++++++++++ fs/gfs2/util.h | 169 ++++++++ 14 files changed, 2804 insertions(+)
fs/gfs2/ops_dentry.c new file +123 -0
@@ -0,0 +1,123 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/completion.h> +#include <linux/buffer_head.h> +#include <linux/smp_lock.h> +#include <linux/gfs2_ondisk.h> +#include <linux/crc32.h> + +#include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" +#include "dir.h" +#include "glock.h" +#include "ops_dentry.h" +#include "util.h" + +/** +* gfs2_drevalidate - Check directory lookup consistency +* @dentry: the mapping to check +* @nd: +* +* Check to make sure the lookup necessary to arrive at this inode from its +* parent is still good. +* +* Returns: 1 if the dentry is ok, 0 if it isn't +*/ + +static int gfs2_drevalidate (struct dentry *dentry,struct nameidata *nd) +{ +struct dentry *parent =dget_parent (dentry); +struct gfs2_sbd *sdp =GFS2_SB (parent->d_inode); +struct gfs2_inode *dip =GFS2_I (parent->d_inode); +struct inode *inode = dentry->d_inode; +struct gfs2_holder d_gh; +struct gfs2_inode *ip; +struct gfs2_inum inum; +unsigned int type; +int error; + +if (inode &&is_bad_inode (inode)) + goto invalid; + +if (sdp->sd_args.ar_localcaching) + goto valid; + + error =gfs2_glock_nq_init (dip->i_gl,LM_ST_SHARED ,0 , &d_gh); +if (error) + goto fail; + + error =gfs2_dir_search (parent->d_inode, &dentry->d_name, &inum, &type); +switch (error) { +case 0 : +if (!inode) + goto invalid_gunlock; +break ; +case -ENOENT : +if (!inode) + goto valid_gunlock; + goto invalid_gunlock; +default : + goto fail_gunlock; + } + + ip =GFS2_I (inode); + +if (!gfs2_inum_equal (&ip->i_num, &inum)) + goto invalid_gunlock; + +if (IF2DT (ip->i_di.di_mode) != type) { +gfs2_consist_inode (dip); + goto fail_gunlock; + } + + valid_gunlock: +gfs2_glock_dq_uninit (&d_gh); + + valid: +dput (parent); +return 1 ; + + invalid_gunlock: +gfs2_glock_dq_uninit (&d_gh); + + invalid: +if (inode &&S_ISDIR (inode->i_mode)) { +if (have_submounts (dentry)) + goto valid; +shrink_dcache_parent (dentry); + } +d_drop (dentry); + +dput (parent); +return 0 ; + + fail_gunlock: +gfs2_glock_dq_uninit (&d_gh); + + fail: +dput (parent); +return 0 ; +} + +static int gfs2_dhash (struct dentry *dentry,struct qstr *str) +{ + str->hash =gfs2_disk_hash (str->name, str->len); +return 0 ; +} + +struct dentry_operations gfs2_dops = { + .d_revalidate = gfs2_drevalidate, + .d_hash = gfs2_dhash, +}; +
fs/gfs2/ops_dentry.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __OPS_DENTRY_DOT_H__ +#define __OPS_DENTRY_DOT_H__ + +extern struct dentry_operations gfs2_dops; + +#endif /* __OPS_DENTRY_DOT_H__ */
fs/gfs2/ops_export.c new file +293 -0
293 lines not on this page · raw message
fs/gfs2/ops_export.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __OPS_EXPORT_DOT_H__ +#define __OPS_EXPORT_DOT_H__ + +extern struct export_operations gfs2_export_ops; +struct gfs2_fh_obj { +struct gfs2_inum this; +__u32 imode; +}; + +#endif /* __OPS_EXPORT_DOT_H__ */
fs/gfs2/ops_super.c new file +472 -0
472 lines not on this page · raw message
fs/gfs2/ops_super.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __OPS_SUPER_DOT_H__ +#define __OPS_SUPER_DOT_H__ + +extern struct super_operations gfs2_super_ops; + +#endif /* __OPS_SUPER_DOT_H__ */
fs/gfs2/ops_vm.c new file +188 -0
188 lines not on this page · raw message
fs/gfs2/ops_vm.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __OPS_VM_DOT_H__ +#define __OPS_VM_DOT_H__ + +extern struct vm_operations_struct gfs2_vm_ops_private; +extern struct vm_operations_struct gfs2_vm_ops_sharewrite; + +#endif /* __OPS_VM_DOT_H__ */
fs/gfs2/super.c new file +979 -0
979 lines not on this page · raw message
fs/gfs2/super.h new file +52 -0
52 lines not on this page · raw message
fs/gfs2/trans.c new file +184 -0
184 lines not on this page · raw message
fs/gfs2/trans.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __TRANS_DOT_H__ +#define __TRANS_DOT_H__ + +#define RES_DINODE 1 +#define RES_INDIRECT 1 +#define RES_JDATA 1 +#define RES_DATA 1 +#define RES_LEAF 1 +#define RES_RG_BIT 2 +#define RES_EATTR 1 +#define RES_STATFS 1 +#define RES_QUOTA 2 + +int gfs2_trans_begin (struct gfs2_sbd *sdp, +unsigned int blocks,unsigned int revokes); + +void gfs2_trans_end (struct gfs2_sbd *sdp); + +void gfs2_trans_add_gl (struct gfs2_glock *gl); +void gfs2_trans_add_bh (struct gfs2_glock *gl,struct buffer_head *bh,int meta); +void gfs2_trans_add_revoke (struct gfs2_sbd *sdp,uint64_t blkno); +void gfs2_trans_add_unrevoke (struct gfs2_sbd *sdp,uint64_t blkno); +void gfs2_trans_add_rg (struct gfs2_rgrpd *rgd); + +#endif /* __TRANS_DOT_H__ */
fs/gfs2/util.c new file +245 -0
245 lines not on this page · raw message
fs/gfs2/util.h new file +169 -0
169 lines not on this page · raw message
fs/gfs2/ops_export.c line 54
Quoted 13 lines
fs/gfs2/ops_export.c new file +12
-0+ this = &fh_obj.this; + fh_obj.imode =DT_UNKNOWN ; +memset (&parent,0 ,sizeof (struct gfs2_inum )); + +switch (fh_type) { +case 10 : + parent.no_formal_ino = ((uint64_t )be32_to_cpu (fh[4 ])) <<32 ; + parent.no_formal_ino |=be32_to_cpu (fh[5 ]); + parent.no_addr = ((uint64_t )be32_to_cpu (fh[6 ])) <<32 ; + parent.no_addr |=be32_to_cpu (fh[7 ]); + fh_obj.imode =be32_to_cpu (fh[8 ]); +case 4 :
What do these constants specify? Would not it be better to have a #define or enum{} for them somewhere?
fs/gfs2/ops_export.c line 185
Quoted 2 lines
fs/gfs2/ops_export.c new file +2
-0+if (IS_ERR (inode)) +return ERR_PTR (PTR_ERR (inode));
Just return inode.
fs/gfs2/ops_super.c line 82
Quoted 2 lines
fs/gfs2/ops_super.c new file +2
-0+if (!strncmp (sb->s_type->name,"gfs2meta" ,8 )) +return ;/* meta fs. don't do nothin' */
Don't nobody go nowhere![1] You see, american negation can be fun, but well, just say: Nothing to do for gfs2meta.
fs/gfs2/ops_super.c line 139
Quoted 1 line
fs/gfs2/ops_super.c new file +1
-0+ sb->s_fs_info =NULL ;
Required?
fs/gfs2/ops_super.c line 154
Quoted 5 lines
fs/gfs2/ops_super.c new file +5
-0+static void gfs2_write_super (struct super_block *sb) +{ +struct gfs2_sbd *sdp = sb->s_fs_info; +gfs2_log_flush (sdp,NULL ); +}
gfs2_log_flush(sb->s_fs_info, NULL)
Quoted 5 lines
fs/gfs2/super.c new file +5
-0+static void gfs2_unlockfs (struct super_block *sb) +{ +struct gfs2_sbd *sdp = sb->s_fs_info; +gfs2_unfreeze_fs (sdp); +}
fs/gfs2/super.c line 282
Quoted 10 lines
fs/gfs2/super.c new file +7
-0+for (x =2 ;; x++) { +uint64_t space, d; +uint32_t m; + + space = sdp->sd_heightsize[x -1 ] * sdp->sd_inptrs; + d = space; + m =do_div (d, sdp->sd_inptrs);
Note for Ingo: simple "/" division does not do it:
11:00 gwdg-wb04A:/dev/shm > cat foo.c
#include <linux/types.h>
uint32_t foo(uint32_t arg) {
uint64_t bar = 1337;
return bar / arg;
}11:00 gwdg-wb04A:/dev/shm > make -C /lib/modules/2.6.17.11-jen33-default/build M=$PWD modules
make: Entering directory /usr/src/linux-2.6.17.11-jen33-obj/i386/default' make -C ../../../linux-2.6.17.11-jen33 O=../linux-2.6.17.11-jen33-obj/i386/default modules
CC [M] /dev/shm/foo.o
Building modules, stage 2.
MODPOST
WARNING: "__udivdi3" [/dev/shm/foo.ko] undefined!
CC /dev/shm/foo.mod.o
LD [M] /dev/shm/foo.ko
make: Leaving directory /usr/src/linux-2.6.17.11-jen33-obj/i386/default'
Quoted 5 lines
+/**
+ *gfs2_assert_warn_i- Print a message to the console if @assertion is false
+ * Returns: -1 if we printed something
+ * -2 if we didn't
+ */
Why not just 0 and 1?
[1] Marvin in "Back To The Future I"
Jan Engelhardt
Signature · 2 lines
-- VGER BF report: U 0.499261
Hi,
Quoted 7 lines · Jan Engelhardt
Quoted 7 lines
fs/gfs2/ops_export.c new file +7
-0+ this = &fh_obj.this; + fh_obj.imode =DT_UNKNOWN ; +memset (&parent,0 ,sizeof (struct gfs2_inum )); + +switch (fh_type) { +case 10 : + parent.no_formal_ino = ((uint64_t )be32_to_cpu (fh[4 ])) <<32 ;
Quoted 9 lines
fs/gfs2/ops_export.c line 54
Quoted 5 lines
fs/gfs2/ops_export.c new file +5
-0+ parent.no_formal_ino |=be32_to_cpu (fh[5 ]); + parent.no_addr = ((uint64_t )be32_to_cpu (fh[6 ])) <<32 ; + parent.no_addr |=be32_to_cpu (fh[7 ]); + fh_obj.imode =be32_to_cpu (fh[8 ]); +case 4 :What do these constants specify? Would not it be better to have a #define or enum{} for them somewhere?
The sizes of the NFS file handles in units of sizeof(u32). I've added a couple of #defines as requested.
Quoted 6 lines
fs/gfs2/ops_export.c line 185
Quoted 3 lines
fs/gfs2/ops_export.c new file +2
-0+if (IS_ERR (inode)) +return ERR_PTR (PTR_ERR (inode));Just return inode.
The function returns a dentry, so it would need to be casted and I thought that would look "more odd" than this construction.
Quoted 10 lines
fs/gfs2/ops_super.c line 82
Quoted 2 lines
fs/gfs2/ops_super.c new file +2
-0+if (!strncmp (sb->s_type->name,"gfs2meta" ,8 )) +return ;/* meta fs. don't do nothin' */ Don't nobody go nowhere![1] You see, american negation can be fun, but well, just say: Nothing to do for gfs2meta.
fs/gfs2/ops_super.c line 139
Quoted 1 line
fs/gfs2/ops_super.c new file +1
-0+ sb->s_fs_info =NULL ;Required?
Both fixed.
Quoted 8 lines
fs/gfs2/ops_super.c line 154
Quoted 5 lines
fs/gfs2/ops_super.c new file +5
-0+static void gfs2_write_super (struct super_block *sb) +{ +struct gfs2_sbd *sdp = sb->s_fs_info; +gfs2_log_flush (sdp,NULL ); +}
gfs2_log_flush(sb->s_fs_info, NULL)
ok.
Quoted 7 lines
fs/gfs2/ops_super.c line 197
Quoted 5 lines
fs/gfs2/ops_super.c new file +5
-0+static void gfs2_unlockfs (struct super_block *sb) +{ +struct gfs2_sbd *sdp = sb->s_fs_info; +gfs2_unfreeze_fs (sdp); +}
I just realised that I missed this one, but it will be in the next patch...
Quoted 21 lines
fs/gfs2/super.c line 282
Quoted 8 lines
fs/gfs2/super.c new file +7
-0+for (x =2 ;; x++) { +uint64_t space, d; +uint32_t m; + + space = sdp->sd_heightsize[x -1 ] * sdp->sd_inptrs; + d = space; + m =do_div (d, sdp->sd_inptrs);Note for Ingo: simple "/" division does not do it:
11:00 gwdg-wb04A:/dev/shm > cat
foo.c
#include <linux/types.h>uint32_t foo(uint32_t arg) { uint64_t bar = 1337; return bar / arg; }
Quoted 14 lines
11:00 gwdg-wb04A:/dev/shm > make -C
/lib/modules/2.6.17.11-jen33-default/buildM=$PWD modules
make: Entering directory/usr/src/linux-2.6.17.11-jen33-obj/i386/default' make -C ../../../linux-2.6.17.11-jen33 O=../linux-2.6.17.11-jen33-obj/i386/default modules
CC [M]/dev/shm/foo.o
Building modules, stage 2.
MODPOST
WARNING: "__udivdi3" [/dev/shm/foo.ko] undefined!
CC/dev/shm/foo.mod.o
LD [M]/dev/shm/foo.ko
make: Leaving directory/usr/src/linux-2.6.17.11-jen33-obj/i386/default'
Yes, I'd spotted this in your email earlier on in the day, so thats why I didn't reply to this thread before.
Quoted 9 lines
Quoted 6 lines
+/**
+ *gfs2_assert_warn_i- Print a message to the console if @assertion is false
+ * Returns: -1 if we printed something
+ * -2 if we didn't
+ */Why not just 0 and 1?
gfs2_assert_warn_i is called from the gfs2_assert_warn macro in util.h. The macro evaluates to 0 in the case that the assert is not triggered, so anything non-zero means that it was triggered, even if nothing was printed. The patch this time is:
Steve.
Quoted 13 lines
Quoted 12 lines
fs/gfs2/ops_export.c line 54
Quoted 9 lines
fs/gfs2/ops_export.c new file +8
-0+switch (fh_type) { +case 10 : + parent.no_formal_ino = ((uint64_t )be32_to_cpu (fh[4 ])) <<32 ; + parent.no_formal_ino |=be32_to_cpu (fh[5 ]); + parent.no_addr = ((uint64_t )be32_to_cpu (fh[6 ])) <<32 ; + parent.no_addr |=be32_to_cpu (fh[7 ]); + fh_obj.imode =be32_to_cpu (fh[8 ]); +case 4 :What do these constants specify? Would not it be better to have a #define or enum{} for them somewhere?
Quoted 2 lines
The sizes of the NFS file handles in units of sizeof(u32). I've added a couple of #defines as requested.
A #define/enum is only really useful if more than one place references it. If this is the only one, just add a comment.
Quoted 7 lines
Quoted 4 lines
fs/gfs2/ops_export.c line 185
Quoted 2 lines
fs/gfs2/ops_export.c new file +2
-0+if (IS_ERR (inode)) +return ERR_PTR (PTR_ERR (inode));Just return inode.
The function returns a dentry, so it would need to be casted and I thought that would look "more odd" than this construction.
Yes, it is very odd indeed that you return an inode as a dentry at all. How is the caller supposed to know whether it was an inode or dentry that was actually returned?
Jan Engelhardt
Hi,
Quoted 12 lines · Jan Engelhardt
Quoted 12 lines
Quoted 11 lines
fs/gfs2/ops_export.c line 54
Quoted 8 lines
fs/gfs2/ops_export.c new file +8
-0+switch (fh_type) { +case 10 : + parent.no_formal_ino = ((uint64_t )be32_to_cpu (fh[4 ])) <<32 ; + parent.no_formal_ino |=be32_to_cpu (fh[5 ]); + parent.no_addr = ((uint64_t )be32_to_cpu (fh[6 ])) <<32 ; + parent.no_addr |=be32_to_cpu (fh[7 ]); + fh_obj.imode =be32_to_cpu (fh[8 ]); +case 4 :What do these constants specify? Would not it be better to have a #define or enum{} for them somewhere?
Quoted 6 lines
Quoted 2 lines
The sizes of the NFS file handles in units of sizeof(u32). I've added a couple of #defines as requested.
A #define/enum is only really useful if more than one place references it. If this is the only one, just add a comment.
There are several places as its used on both the fh encoding and fh decoding routines.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
fs/gfs2/ops_export.c line 185
Quoted 2 lines
fs/gfs2/ops_export.c new file +2
-0+if (IS_ERR (inode)) +return ERR_PTR (PTR_ERR (inode));Just return inode.
The function returns a dentry, so it would need to be casted and I thought that would look "more odd" than this construction.
Quoted 6 lines
Yes, it is very odd indeed that you return an inode as a dentry at all. How is the caller supposed to know whether it was an inode or dentry that was actually returned?
Jan Engelhardt
This is dealing with the error case only. If the function being called returns an error (signaled by IS_ERR(inode) - hence an invalid pointer value) then we need to return that error to the calling routing. Since this function in question returns a dentry, we convert the invalid pointer value from the function returning an inode into an integer and then covert the integer into an invalid pointer value again, but this time its an invalid pointer to a dentry and hence the correct return type for this function.
So the caller of this function will get a pointer to a dentry which will either be a valid dentry pointer or an error value testable with IS_ERR().
Steve.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
fs/gfs2/ops_export.c line 185
Quoted 3 lines
fs/gfs2/ops_export.c new file +2
-0+if (IS_ERR (inode)) +return ERR_PTR (PTR_ERR (inode));Just return inode.
The function returns a dentry, so it would need to be casted and I thought that would look "more odd" than this construction.
Quoted 7 lines
Quoted 4 lines
Yes, it is very odd indeed that you return an inode as a dentry at all. How is the caller supposed to know whether it was an inode or dentry that was actually returned?
This is dealing with the error case only. If the function being called returns an error (signaled by
IS_ERR(inode)- hence an invalid pointer
Seems reasonable. Would you like to add a comment? (Possibly a little shorter than this good explanation, maybe
/* In case of an error, @inode carries the error value, and we have to return that. */
Quoted 6 lines
value) then we need to return that error to the calling routing. Since this function in question returns a dentry, we convert the invalid pointer value from the function returning an inode into an integer and then covert the integer into an invalid pointer value again, but this time its an invalid pointer to a dentry and hence the correct return type for this function.
Jan Engelhardt