Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 96 23:04:54 +0900
From:      Mihoko Tanaka <m_tanaka@pa.yokogawa.co.jp>
To:        freebsd-hackers@freebsd.org
Subject:   NFS trouble ?
Message-ID:  <9601231404.AA28044@cabbage.pa.yokogawa.co.jp>

next in thread | raw e-mail | index | archive | help

Hello All,

My friend is developping a program which seek a file and read it.
Her program seeks a file with a wrong offset (i.e the offset size is larger
than the file size). It occurs panic.

When a file is on a local disk, nothing happens.
But when a file is on NFS, it occurs panic everytime.

She use FreeBSD-2.1.0R.

I make a sample program for it.
--------- cut cut cut ---------------------- cut cut cut -----------------
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

main(int argc, char **argv)
{
	int fd;
	char buf[100];
	off_t ret;
	extern int errno;

	if((fd = open(argv[1], O_RDONLY, 0644)) < 0) {
		perror("open fail");
		exit(1);
	}
	printf("open is succeed!\n");

	if ((ret = lseek(fd, 0x90000000, SEEK_SET)) < 0) {
		fprintf(stderr, "errno = %d, ret = 0x%x \n", errno, ret);
		perror("seek fail");
		exit(1);
	}

	printf("seek is succeed! ret = 0x%x\n", ret);

	if (read(fd, buf, 100)<0) {
		perror("read fail");
		exit(1);
	}
	printf("read is succeed!\n");

	close(fd);
}
--------- cut cut cut ---------------------- cut cut cut -----------------

lseek(2) and read(2) are succeed, when a file is on a local disk.
When a file is on NFS, then lseek(2) is succeed. read(2) occurs
PANIC.

the I/F of lseek(2) is the following :
     off_t lseek(int fd, off_t offset, int whence)

off_t is defined in /usr/include/sys/types.h : 
    typedef long long     off_t

then
	off_t offset = 0x90000000 > 0

I guess that lseek should return a error (EINVAL) when 'offset' is
larger then the file size . 
What do you think ?

How should I avoid this trouble ?
Of course, I know that her program has a bug ! :-)




(kgdb) bt
#0  boot (howto=256) (../../i386/i386/machdep.c line 892)
892                                     dumppcb.pcb_ptd = rcr3();

#1  0xf0117e65 in panic (fmt=(char *) 0xf01a2212 "because you said
to!") (../../kern/subr_prf.c line 124)

#2  0xf01a2235 in diediedie () (../../i386/i386/machdep.c line 834)

#3  0xf01014de in db_fncall (dummy1=1, dummy2=0, dummy3=-266292708,
dummy4=(char *) 0xefbffbd4 "\304\016!\360d\307!\360")
(../../ddb/db_command.c line 491) 

#4  0xf0101212 in db_command (last_cmdp=(struct command **)
0xf01f8af4, cmd_table=(struct command *) 0xf01f8954)
(../../ddb/db_command.c line 281) 

#5  0xf0101391 in db_command_loop () (../../ddb/db_command.c line 419)

#6  0xf0103e7c in db_trap (type=12, code=0) (../../ddb/db_trap.c line 72)

#7  0xf019f3ce in kdb_trap (type=12, code=0, regs=(struct trapframe
*) 0xefbffd28) (../../i386/i386/db_interface.c line 120) 

#8  0xf01aa31b in trap_fatal (frame=(struct trapframe *) 0xefbffd28)
(../../i386 
/i386/trap.c line 741)

#9  0xf01a9e98 in trap_pfault (frame=(struct trapframe *)
0xefbffd28, usermode=0) (../../i386/i386/trap.c line 667) 

#10 0xf01a9ae7 in trap (frame={tf_es = 16, tf_ds = 16, tf_edi =
-227674456, tf_esi = 0, tf_ebp = -272630384, tf_isp = -267213461,
tf_ebx = -257278388, tf_edx = 2147483647, tf_ecx = -227674456,
tf_eax = 0, tf_trapno = 12, tf_err = 0, tf_eip = -267213461, tf_cs =
8, tf_eflags = 66071, tf_esp = -227674456, tf_ss = -2147483648})
(../../i386/i386/trap.c line 307) 

#11 0xf019fc9d in exception:calltrap ()

#12 0xf012a56b in allocbuf (bp=(struct buf *) 0xf26df6a8,
size=268441088) (../../kern/vfs_bio.c line 1052) 

#13 0xf012a19b in getblk (vp=(struct vnode *) 0xf173da00,
blkno=491520, size=268441088, slpflag=0, slptimeo=0)
(../../kern/vfs_bio.c line 910) 

#14 0xf014fdfe in nfs_getcacheblk (vp=(struct vnode *) 0xf173da00,
bn=491520, size=268441088, p=(struct proc *) 0xf1682500)
(../../nfs/nfs_bio.c line 602) 

#15 0xf014f106 in nfs_bioread (vp=(struct vnode *) 0xf173da00,
uio=(struct uio *
) 0xefbfff2c, ioflag=0, cred=(struct ucred *) 0xf1521500)
(../../nfs/nfs_bio.c line 240) 

#16 0xf01677f3 in nfs_read (ap=(struct vop_read_args *) 0xefbffee0)
(../../nfs/nfs_vnops.c line 817) 

#17 0xf0132b4a in vn_read (fp=(struct file *) 0xf1780ec0,
uio=(struct uio *) 0xefbfff2c, cred=(struct ucred *) 0xf1521500)
(./vnode_if.h line 211) 

#18 0xf011918b in read (p=(struct proc *) 0xf1682500, uap=(struct
read_args *) 0xefbfff94, retval=(int *) 0xefbfff8c)
(../../kern/sys_generic.c line 112) 

#19 0xf01aa57f in syscall (frame={tf_es = 39, tf_ds = 39, tf_edi =
0, tf_esi = -272639016, tf_ebp = -272639052, tf_isp = -272629788,
tf_ebx = -272639012, tf_edx = 134689284, tf_ecx = 134689284, tf_eax
= 3, tf_trapno = 662, tf_err = 662, tf_eip = 134623909, tf_cs = 31,
tf_eflags = 662, tf_esp = -272639172, tf_ss = 39})
(../../i386/i386/trap.c line 878) 
(kgdb) 


--
Mihoko Tanaka 
<m_tanaka@pa.yokogawa.co.jp>     
	



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9601231404.AA28044>