[OpenAFS-devel] Client bug in afs_segments.c
Christof Hanke
hanke@rzg.mpg.de
Fri, 10 Sep 2004 13:20:47 +0200 (CEST)
Hello List,
together with a user and Hartmut, I guess I found a bug in the function
afs_TruncateAllSegments() in afs_segments.c.
Basically, the pointers (struct dcache *)->validPos and (struct dcache *)->=
f.chunkBytes are not kept in sync.
Here the patch :
diff -ur /usr/src/openafs-1.3.71/src/afs/afs_segments.c afs_segments.c
--- /usr/src/openafs-1.3.71/src/afs/afs_segments.c 2004-08-25 09:09:32=
=2E000000000 +0200
+++ afs_segments.c 2004-09-10 12:18:08.000000000 +0200
@@ -1041,6 +1041,12 @@
afs_CFileTruncate(tfile, newSize);
afs_CFileClose(tfile);
afs_AdjustSize(tdc, newSize);
+ if (alen < tdc->validPos) {
+ if (alen < AFS_CHUNKTOBASE(tdc->f.chunk))
+ tdc->validPos =3D 0;
+ else
+ tdc->validPos =3D alen;
+ }
ConvertWToSLock(&tdc->lock);
}
ReleaseSharedLock(&tdc->lock);
My guess is that the same bug is in the 1.2.x-series as well.
The consequences of this bug can be tested with this program
(you have to set the macro !) :
On rh9 or suse 9.0 on a single CPU machine it gives an i/o-error,
a SMP machine freezes. (At least for me)
=20
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#define FILE_IN_AFS "ABSOLUTE_PATH_TO_AFS_FILE"
int main() {
FILE *fp;
int i,fd;
char fname[]=3D FILE_IN_AFS;
char pr_string[]=3D" Hallo\n";
off_t size=3D0;
fp =3Dfopen(fname,"w+");
for (i=3D0;i < 1000;i++)
fprintf(fp," Hallo\n");
fclose(fp);
fp =3Dfopen(fname,"a");
fd=3Dfileno(fp);
rewind(fp);
for (i=3D0;i < 50;i++)
size+=3Dsizeof(pr_string);
fprintf(fp,pr_string);
fflush(fp);
ftruncate(fd,size);
fclose(fp);
return 0;
}
I hope that helps.
Christof Hanke
-----------------------------------------------------------------
Christof Hanke =09=09e-mail hanke@rzg.mpg.de
RZG (Rechenzentrum Garching)=09=09phone +49-89-3299-1788
Computing Center of the Max-Planck-Gesellschaft (MPG) and the
Institut f=FCr Plasmaphysik (IPP)