[3892] in linux-scsi channel archive
Nonblocking writes to sg* can block (2.1.98)
daemon@ATHENA.MIT.EDU (Ian Jackson)
Mon May 11 11:46:03 1998
Date: Mon, 11 May 1998 16:34:12 +0100 (BST)
From: Ian Jackson <iwj@ncipher.com>
To: linux-scsi@vger.rutgers.edu
(I initially posted this to linux-kernel, thinking linux-scsi was
dead because my local gateway was broken. I think it's better placed
here. NB that though `iwj@ncipher.com' and
`ijackson@chiark.greenend.org.uk' are the same human being, I'm
wearing different hats. Please send responses to the right place.)
We manufacture a SCSI processor device, and supply software which
drives it via the /dev/sg* interface on Linux. The device has two
LUNs, 0 and 1, and our driver program `hardserver' talks to both,
often issuing commands to both LUNs at once. We set O_NONBLOCK using
fcntl, to make sure that the hardserver cannot block if for any reason
one of the sg* devices blocks on a read or write.
However, with Linux 2.1.98 SMP on RH5 this does not work correctly.
See the strace transcript below. Our program opens its devices, does
an Inquiry on the first device to check that it's the right one, and
then sets O_NONBLOCK on both. It waits for a client program to
connect, and then talks to the hardware, sending in quick succession
long writes of commands to both devices. The second write blocks,
despite the O_NONBLOCK flag; if it returned EAGAIN instead our server
would queue the data internally and use select() to determine when to
try again.
If you hit ^C strace reports the write returning with ENOMEM (though
the hardserver itself does not trap SIGINT, so not under strace it
will just kill the process).
See also the /proc/scsi/scsi info and kernel messages. There are no
kernel messages generated during the failure.
Thanks,
Ian.
[root@saintpaul sbin]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: SEAGATE Model: ST19101W Rev: 0014
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: TOSHIBA Model: CD-ROM XM-6201TA Rev: 1030
Type: CD-ROM ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: nCipher Model: Fastness Crypto Rev: 1.33
Type: Processor ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 01
Vendor: nCipher Model: Fastness Crypto Rev: 1.33
Type: Processor ANSI SCSI revision: 02
[root@saintpaul sbin]#
May 7 12:49:05 saintpaul kernel: (scsi0:0:2:0) Refusing synchronous negotiation; using asynchronous transfers.
May 7 12:49:05 saintpaul kernel: Vendor: nCipher Model: Fastness Crypto Rev: 1.33
May 7 12:49:05 saintpaul kernel: Type: Processor ANSI SCSI revision: 02
May 7 12:49:05 saintpaul kernel: Detected scsi generic sgc at scsi0, channel 0, id 2, lun 0
May 7 12:49:05 saintpaul kernel: Vendor: nCipher Model: Fastness Crypto Rev: 1.33
May 7 12:49:05 saintpaul kernel: Type: Processor ANSI SCSI revision: 02
May 7 12:49:05 saintpaul kernel: Detected scsi generic sgd at scsi0, channel 0, id 2, lun 1
May 7 12:49:05 saintpaul kernel: scsi : detected 1 SCSI cdrom 1 SCSI disk total.
[ I later did a modprobe sg, since our sg driver is modularised. ]
execve("./hardserver", ["./hardserver"], [/* 16 vars */]) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40006000
mprotect(0x8048000, 230650, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=3262, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY) = 4
mmap(0, 3262, PROT_READ, MAP_SHARED, 4, 0) = 0x40007000
close(4) = 0
open("/lib/libc.so.5.3.12", O_RDONLY) = 4
read(4, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3"..., 4096) = 4096
mmap(0, 831488, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40008000
mmap(0x40008000, 599154, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 0) = 0x40008000
mmap(0x4009b000, 22664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 4, 0x92000) = 0x4009b000
mmap(0x400a1000, 200812, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400a1000
close(4) = 0
mprotect(0x40008000, 599154, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
munmap(0x40007000, 3262) = 0
mprotect(0x8048000, 230650, PROT_READ|PROT_EXEC) = 0
mprotect(0x40008000, 599154, PROT_READ|PROT_EXEC) = 0
personality(PER_LINUX) = 0
geteuid() = 0
getuid() = 0
getgid() = 0
getegid() = 0
socket(PF_UNIX, SOCK_STREAM, 0) = 4
time(NULL) = 894544443
open("/usr/lib/zoneinfo/localtime", O_RDONLY) = 5
read(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 6460) = 1322
close(5) = 0
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Using sock"..., 54) = 54
unlink("/dev/nfast/nserver") = 0
bind(4, {sun_family=AF_UNIX, sun_path="/dev/nfast/nserver"}, 110) = 0
listen(4, 5) = 0
chmod("/dev/nfast/nserver", 0666) = 0
fcntl(4, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0
socket(PF_UNIX, SOCK_STREAM, 0) = 5
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Using priv"..., 69) = 69
unlink("/dev/nfast/priv/privnserver") = 0
bind(5, {sun_family=AF_UNIX, sun_path="/dev/nfast/priv/privnserver"}, 110) = 0
listen(5, 5) = 0
chmod("/dev/nfast/priv/privnserver", 0666) = 0
fcntl(5, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK) = 0
unlink("/dev/nfast/server") = 0
symlink("/dev/nfast/nserver", "/dev/nfast/server") = 0
open(0xbffffce8, O_RDWR) = 6
open(0xbffffc84, O_RDWR) = 7
[ it is opening /dev/sgc (LUN 0) and sgd (LUN 1) here. strace reports:
ptrace: umoven: I/O error
for no readily apparent reason. ]
write(6, "*\0\0\0\204\0\0\0\0\0\0\0\0\0\0\0"..., 42) = 42
read(6, "\204\0\0\0\204\0\0\0\0\0\0\0\0\0"..., 132) = 132
fcntl(6, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK) = 0
fcntl(7, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0
brk(0x8085d28) = 0x8085d28
brk(0x8086000) = 0x8086000
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Found devi"..., 85) = 85
brk(0x8087000) = 0x8087000
open(0xbffffce8, O_RDWR) = -1 ENOENT (No such file or directory)
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: open devic"..., 44) = 44
sigaction(SIGPIPE, {SIG_IGN}, NULL) = 0
sigaction(SIGUSR1, {0x804e350, [], 0}, NULL) = 0
gettimeofday({894544443, 849604}, NULL) = 0
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Server sta"..., 53) = 53
write(6, "*\2\0\0$\0\0\0\1\0\0\0\0\0\0\0\0"..., 554) = 554
gettimeofday({894544443, 850473}, NULL) = 0
gettimeofday({894544443, 850575}, NULL) = 0
write(7, "*\0\0\0$ \0\0\2\0\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(8, [4 5 6 7], [], NULL, {1, 999898}) = 1 (in [6], left {2, 0})
read(6, "$\0\0\0$\0\0\0\1\0\0\0\0\0\0\0\0"..., 36) = 36
gettimeofday({894544443, 851581}, NULL) = 0
oldselect(8, [4 5 6 7], [], NULL, {1, 998892}) = 1 (in [7], left {2, 0})
read(7, "$ \0\0$ \0\0\2\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Device #1 "..., 204) = 204
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Device #1 "..., 79) = 79
brk(0x808a000) = 0x808a000
time(NULL) = 894544443
write(2, "1998-05-07 13:34:03 ", 20) = 20
write(2, "NFast server: Notice: Server ope"..., 52) = 52
gettimeofday({894544443, 857473}, NULL) = 0
write(7, "*\0\0\0$ \0\0\3\0\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(8, [4 5 6 7], [], NULL, {1, 993000}) = 1 (in [7], left {1, 990000})
read(7, "$ \0\0$ \0\0\3\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
gettimeofday({894544443, 860875}, NULL) = 0
oldselect(8, [4 5 6], [], NULL, {1, 989598}) = 0 (Timeout)
gettimeofday({894544445, 859808}, NULL) = 0
gettimeofday({894544445, 859907}, NULL) = 0
oldselect(8, [4 5 6], [], NULL, {1, 999901}) = 0 (Timeout)
gettimeofday({894544447, 869809}, NULL) = 0
write(6, "*\2\0\0$\0\0\0\4\0\0\0\0\0\0\0\0"..., 554) = 554
gettimeofday({894544447, 870139}, NULL) = 0
write(7, "*\0\0\0$ \0\0\5\0\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(8, [4 5 6 7], [], NULL, {1, 999670}) = 1 (in [6], left {2, 0})
read(6, "$\0\0\0$\0\0\0\4\0\0\0\0\0\0\0\0"..., 36) = 36
gettimeofday({894544447, 871164}, NULL) = 0
oldselect(8, [4 5 6 7], [], NULL, {1, 998645}) = 1 (in [7], left {2, 0})
read(7, "$ \0\0$ \0\0\5\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
gettimeofday({894544447, 873708}, NULL) = 0
write(7, "*\0\0\0$ \0\0\6\0\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(8, [4 5 6 7], [], NULL, {1, 996101}) = 1 (in [7], left {2, 0})
read(7, "$ \0\0$ \0\0\6\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
gettimeofday({894544447, 876884}, NULL) = 0
oldselect(8, [4 5 6], [], NULL, {1, 992925}) = 0 (Timeout)
gettimeofday({894544449, 879815}, NULL) = 0
gettimeofday({894544449, 879914}, NULL) = 0
oldselect(8, [4 5 6], [], NULL, {1, 999901}) = 1 (in [4], left {1, 240000})
accept(4, {sun_family=AF_UNIX, sun_path=""}, [2]) = 8
fcntl(8, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(8, F_SETFL, O_RDWR|O_NONBLOCK) = 0
brk(0x808d000) = 0x808d000
time(NULL) = 894544450
write(2, "1998-05-07 13:34:10 ", 20) = 20
write(2, "NFast server: Notice: New client"..., 46) = 46
gettimeofday({894544450, 643891}, NULL) = 0
oldselect(9, [4 5 6 8], [], NULL, {1, 235924}) = 1 (in [8], left {1, 240000})
read(8, "\30\0\0\0\0\1\317\27\25\0\0\0\0\0"..., 8192) = 24
write(6, "*\2\0\0$\0\0\0\7\0\0\0\0\0\0\0\0"..., 554) = 554
gettimeofday({894544450, 645382}, NULL) = 0
write(7, "*\0\0\0$ \0\0\10\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(9, [4 5 6 7 8], [], NULL, {1, 234433}) = 1 (in [6], left {1, 240000})
read(6, "$\0\0\0$\0\0\0\7\0\0\0\0\0\0\0\0"..., 36) = 36
gettimeofday({894544450, 646561}, NULL) = 0
oldselect(9, [4 5 6 7 8], [], NULL, {1, 233254}) = 1 (in [7], left {1, 240000})
read(7, "$ \0\0$ \0\0\10\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
write(8, ",\0\0\0\0\1\317\27\25\0\0\0\0\0\0"..., 44) = 44
gettimeofday({894544450, 649929}, NULL) = 0
write(7, "*\0\0\0$ \0\0\t\0\0\0\0\0\0\0\0\0"..., 42) = 42
oldselect(9, [4 5 6 7 8], [], NULL, {1, 229886}) = 1 (in [8], left {1, 230000})
read(8, " \0\0\0\1\1\317\0275\0\0\0\0\0\0"..., 8192) = 32
write(8, "\210\0\0\0\1\1\317\0275\0\0\0\0\0"..., 136) = 136
gettimeofday({894544450, 651298}, NULL) = 0
oldselect(9, [4 5 6 7 8], [], NULL, {1, 228517}) = 2 (in [7 8], left {1, 230000})
read(7, "$ \0\0$ \0\0\t\0\0\0\0\0\0\0\0\0"..., 8228) = 8228
read(8, "\240\1\0\0\2\1\317\27\1\0\0\0\0\0"..., 8192) = 8192
write(6, "*\34\0\0$\0\0\0\n\0\0\0\0\0\0\0\0"..., 7210) = 7210
gettimeofday({894544450, 654797}, NULL) = 0
write(7, "*\0\0\0$ \0\0\v\0\0\0\0\0\0\0\0\0"..., 42
[ blocks here, until I hit ^C ]
) = -1 ENOMEM (Out of memory)
--- SIGINT (Interrupt) ---
+++ killed by SIGINT +++
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.rutgers.edu