[PVFS-developers] metadata file size checking
Rob Ross
rross at mcs.anl.gov
Wed May 19 12:24:33 EDT 2004
Don,
I've applied your patch to CVS, but I'm thinking I might simplify this a
bit more before we're done.
Here's what I'm thinking: rather than having meta_creat() call meta_open()
at the end, just have it explicitly re-open on its own. This will allow
us to avoid the extra write() of dummy data.
I've attached a patch. Lemme know what you think. Sorry that there is
formatting junk in there that is distracting from the real purpose.
And thanks for the original patch!
Rob
On Thu, 6 May 2004, Porter Don wrote:
> I wanted to implement some protection against overwriting a metadata file
> that has not had the migration script run on it after an upgrade. So I
> ended up stat-ing the file in meta-open and if it is not a directory and its
> size is not the same as a struct fmeta, then the manager will return an
> EINVAL (open to suggestions for better error code) and print a message to
> logs. See below:
-------------- next part --------------
Index: mgr/meta/metaio.c
===================================================================
RCS file: /projects/cvsroot/pvfs/mgr/meta/metaio.c,v
retrieving revision 1.18
diff -r1.18 metaio.c
83c83,84
< if(0 > stat(pathname, &st)){
---
> if (stat(pathname, &st) < 0)
> {
88,89c89,92
< if(S_ISREG(st.st_mode) && st.st_size != sizeof(struct fmeta)){
< fprintf(stderr, "Cowardly refusing to open %s because it is not the size I expect a metadata file to be.\n", pathname);
---
> if (S_ISREG(st.st_mode) && st.st_size != sizeof(struct fmeta))
> {
> fprintf(stderr, "Cowardly refusing to open %s because it is not the size I expect a metadata file to be.\n",
> pathname);
108,110c111,112
< static struct fmeta fm;
< int fd, old_umask, cflags = O_RDWR | O_CREAT | O_EXCL,
< mode = S_IRWXU | S_IRGRP | S_IROTH;
---
> int fd, old_umask, cflags = O_RDWR | O_CREAT | O_EXCL;
> int mode = S_IRWXU | S_IRGRP | S_IROTH;
116c118
< if(fd < 0){
---
> if (fd < 0) {
119,127d120
<
< /* write in dummy fmeta so that meta_open will succeed. This is ok
< * because only md_open calls us directly and it will overwrite
< * anyway
< */
< if(sizeof(struct fmeta) != write(fd, &fm, sizeof(struct fmeta))){
< return(-1);
< }
<
131c124,125
< return(meta_open(pathname, flags));
---
> flags &= ~O_CREAT;
> return(open(pathname, flags, 0));
More information about the PVFS-developers
mailing list