if we use pread/write we don't need to protect the kernel's file pointer with a qlock, and that code can go away. Reference: /n/atom/patch/applied2013/kfspwrite Date: Fri Oct 25 03:13:25 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/disk/kfs/devwren.c Fri Oct 25 03:12:44 2013 +++ /sys/src/cmd/disk/kfs/devwren.c Fri Oct 25 03:12:44 2013 @@ -9,7 +9,6 @@ typedef struct Wren Wren; struct Wren{ - QLock; Device dev; uvlong size; int fd; @@ -49,8 +48,7 @@ panic("can't open %s", wrenfile); if((d = dirfstat(fd)) == nil) panic("can't stat %s\n", wrenfile); - seek(fd, 0, 0); - i = read(fd, buf, sizeof buf); + i = pread(fd, buf, sizeof buf, 0); if(i < sizeof buf) panic("can't read %s", wrenfile); badmagic = 0; @@ -87,9 +85,7 @@ fd = w->fd; memset(buf, 0, sizeof buf); sprint(buf+256, "%s%d\n", WMAGIC, RBUFSIZE); - qlock(w); - i = seek(fd, 0, 0) < 0 || write(fd, buf, RBUFSIZE) != RBUFSIZE; - qunlock(w); + i = pwrite(fd, buf, RBUFSIZE, 0) != RBUFSIZE; if(i < 0) panic("can't ream disk"); } @@ -149,11 +145,9 @@ w = wren(dev); fd = w->fd; - qlock(w); - i = seek(fd, (vlong)addr*RBUFSIZE, 0) == -1 || read(fd, b, RBUFSIZE) != RBUFSIZE; - qunlock(w); + i = pread(fd, b, RBUFSIZE, (vlong)addr*RBUFSIZE) != RBUFSIZE; if(i) - print("wrenread failed: %r\n"); + print("wrenread failed byte %lld: %r\n", (vlong)addr*RBUFSIZE); return i; } @@ -165,10 +159,8 @@ w = wren(dev); fd = w->fd; - qlock(w); - i = seek(fd, (vlong)addr*RBUFSIZE, 0) == -1 || write(fd, b, RBUFSIZE) != RBUFSIZE; - qunlock(w); + i = pwrite(fd, b, RBUFSIZE, (vlong)addr*RBUFSIZE) != RBUFSIZE; if(i) - print("wrenwrite failed: %r\n"); + print("wrenwrite failed byte %lld: %r\n", (vlong)addr*RBUFSIZE); return i; }