Artsize still not quite right in CURRENT

Alex Kiernan alexk at demon.net
Wed Apr 18 03:59:17 UTC 2001


davidsen at tmr.com (bill davidsen) writes:

> In article <721yqsez2t.fsf at nd1.eng.demon.net>,
> Alex Kiernan  <alexk at demon.net> wrote:
> | 
> | davidsen at tmr.com (bill davidsen) writes:
> 
> | >   In any case, if that's the problem, unless there's a huge gain in
> | > {something} by using pread, perhaps we can revert the code, or put in a
> | > conditional, or whatever.
> | > 
> | 
> | How about writing a configure test which checks for broken
> | implementations and falls back to the version in lib (which emulates
> | using lseek & read, so should work).
> 
> I'm in favor of it, but it's an interesting test to devise. I think we
> want to determine if the kernel or library is broken first.
> 

Can you try this, building it with appropriate 64 bit flags & running
it on a file system which allows 64 bit operations:

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int
main(void)
{
    int fd;
    uint32_t cookie0 = 0xdeadbeef, cookie4g = 0x0badc0de, cookie;
    unsigned long long offset = (long long)4*1024*1024*1024;
    const char *testfile = "prwtestfile";

    /* assume lseek/write work */
    fd = open(testfile, O_CREAT|O_RDWR|O_TRUNC, 0777);
    if (fd == -1)
	perror("can't create testfile");
    if (write(fd, &cookie0, sizeof cookie0) != sizeof cookie0)
	perror("write1");
    if (lseek(fd, offset, SEEK_SET) != offset)
	perror("lseek");
    if (write(fd, &cookie4g, sizeof cookie4g) != sizeof cookie4g)
	perror("write2");
    if (close(fd) == -1)
	perror("close");

    /* try pread */
    fd = open(testfile, O_RDONLY);
    if (fd == -1)
	perror("can't open testfile");
    if (pread(fd, &cookie, sizeof cookie, offset) != sizeof cookie ||
	cookie != cookie4g)
	fprintf(stderr, "pread broken - wrote %x, read %x\n",
		cookie4g, cookie);
    if (close(fd) == -1)
	perror("close");
    if (unlink(testfile) == -1)
	perror("unlink");
    return 0;
}

I don't have a Linux box to test on, but I've tried Solaris 7 &
FreeBSD 4.3-RC2 where it works on both (which isn't really the
point!). If the test succeeds (i.e. pread works), it says nothing, if
not it should report something like:

pread broken - wrote badc0de, read deadbeef

If it sucessfully detects the problem I'll roll it into something we
can drop into configure (plus checks for pwrite, lib/pread &
lib/pwrite).

> | The problem with going back (well its not a problem today) is that
> | unless you put mutexes around your lseeks & reads you can't use it in
> | a threaded environment (without having a set of file handles per
> | thread). A threaded nnrpd is one of the things I've been playing with.
> 
> I don't know about anyone else, but my efforts are going into trying to
> get news into the box, not out!
> 

For news in I'm going for throwing big iron at the problem (since you
only need one or two of those, so its "cheap"), news out I can't
afford to throw enough big iron at the problem (for the reader
population I need to support), so I have to reduce the cost of the
readers some other way.

-- 
Alex Kiernan, Principal Engineer, Development, Thus PLC


More information about the inn-workers mailing list