lkml.org 
[lkml]   [2000]   [Mar]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subjectdata corruption through nfs
Date
(test programs are attached at the end)

We are experiencing strange data corruption problems using RH6.1 nfs client and
Solaris nfs server (SunOS 5.6). Later it is also found that same problem happened
on RH6.1 nfs server too, with much less frequency. This is likely to be a nfs
problem (not clear client or server) because it won't happen if running on
local disks. We hope we can get help by distributing the problem.

The symptom is as this:
If do the following procedure:
1. A data block is first written to file
2. Then write a large amount of data following the block
3. Use fseek to seek back to the data block and update with new values,

at the 3rd step, sometimes the data block is failed to be updated.

The interesting thing is that if we use fopen(<name>,"w+") instead of
using "w", there are much less failures (almost none on Soloaris, but
some on RH6.1 nfs server). We don't know why.

Things to note:
. all file handling is using fstream with fopen, fseek, ftell, fwrite. No
error messages are reported when data corrupted
. fflush() doesn't help at all.
. the problem seems to be non-deterministic, meaning it doesn't happen
all the time and it doesn't necessarily happen at the same place. This
also makes debugging difficult.
. the problem won't happen when writing to local disk

Any response for solutions or same experiences would be appreciated. Please
make sure you also send your answer to my email address. Thanks in advance.

Daben

PS
The following are two programs that demonstrate the problem. testw.c
will do the above procedure 100 times. The data block is a integer initialized
to zero and updated to non-zero. testr.c will check the output file
and exit if it finds that the data block remains zero. An example output of
running testr program:

*** READ TOC hoff = 16808
*** READ TOC hoff = 24700
*** READ TOC hoff = 40366
*** READ TOC hoff = 56339
*** READ TOC hoff = 74576
*** READ TOC hoff = 0
wrong = 1

which says the testw.c program fails at the 6th iteration.

--- test programs ------

/********************************************/
/* testw.c write data */
/********************************************/
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int i,j;
int dim; /* random number of data in the buffer */
char *data; /* buffer */
FILE *fp = fopen("test.dat","w");
long start;
int hoff; /* the data block to be updated */

data = (char *)calloc(20003, sizeof(char));

for (i=0;i<100;i++) {
/* initial hoff and write to file*/
hoff = 0;
if (fseek(fp, 0L, 2) == -1) /* seek to the end */
fprintf(stderr, "fseek cannot get to the end\n");
if ((start = ftell(fp)) == -1) /* remember the location */
fprintf(stderr, "ftell failed\n");
if ((fwrite(&hoff, sizeof(int), 1, fp)) != 1) /* write the first time */
fprintf(stderr, "fwrite failed\n");

/* write data, random pick data size, bug triggered with big size */
dim = 1+(int) (20000.0*rand()/(RAND_MAX+1.0));
for (j=0;j<dim;j++) data[j] = 'D';
if ((fwrite((void *)data, sizeof(char), dim, fp)) != dim)
fprintf(stderr, "fwrite data failed\n");
fflush(fp);

/* change hoff, let it register the current FILE pointer location */
if ((hoff = ftell(fp)) == -1)
fprintf(stderr, "ftell failed\n");

/* re-write hoff at the beginning, buggy part */
if(fseek(fp,start,0) == -1)
fprintf(stderr, "fseek back to the beginning failed\n");
if((fwrite(&hoff, sizeof(int), 1, fp)) != 1)
fprintf(stderr, "fwrite rewriting failed\n");;

}

fclose(fp);
free(data);
return 0;
}

------- the following is the read program to validate the output file ------
/*************************************************************/
/* testr.c : read file test.dat */
/*************************************************************/
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
FILE *fp;
int hoff;
int i;
int wrong = 0;

fp = fopen("test.dat","r");

for (i=0;i<100;i++) {
fread(&hoff, sizeof(char), sizeof(int), fp);
printf("*** READ TOC hoff = %ld \n",hoff);
if (hoff == 0) {
wrong ++;
break;
}
fseek(fp,hoff,0);
}

fclose(fp);

printf("wrong = %d\n",wrong);
return 0;
}

------------------------------------------------------------
BBN Technologies
70 Fawcett Street, Cambridge, MA 02138
Tel: (617)873-3636




-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.051 / U:0.620 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site