NFS and soft mount - NFS

This is a discussion on NFS and soft mount - NFS ; Hi, I want to make an application that writes files on an NFS shared folder, but : 1) I want to know if the data has been successfully written 2) The "write" function must not be "blocking" 3) The data ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: NFS and soft mount

  1. NFS and soft mount

    Hi,

    I want to make an application that writes files on an NFS shared
    folder, but :
    1) I want to know if the data has been successfully written
    2) The "write" function must not be "blocking"
    3) The data to write must not be queued (no async)
    4) I want to detect disconnections with the server
    5) Like the writing is done in a thread i would like to not use signals
    (no intr)

    I have put the following options to mount :
    timeo=10,retrans=1,fg,soft,udp,sync but when i disconnect the server
    (deactivate NFS server), the write function on the file on the NFS
    shared folder returns alternatively error and successful operation (the
    function returns the number of bytes to write). It also returns
    approximatively after one minute (I want to control this time ...).

    For example the following program returns alternatively OK 7 and KO
    altough the server is not accessible
    fd = open(DEST "/TEST.log", O_CREAT|O_WRONLY|O_TRUNC|O_SYNC);
    if (fd != -1)
    {
    for(;
    {
    /* ............. */
    iWrite = write(fd, "Hello \r\n", 7);
    if (iWrite == -1)
    {
    printf("KO\n\n");
    }
    else
    {
    printf("OK %d\n\n", iWrite);
    }
    }
    }

    Thanks,
    Rémi


  2. Re: NFS and soft mount


    Rezaa wrote:
    > Hi,
    >
    > I want to make an application that writes files on an NFS shared
    > folder, but :
    > 1) I want to know if the data has been successfully written


    Do you also want to know the data has not been written?

    > 2) The "write" function must not be "blocking"


    Not much you can do about that, especially considering
    your next requirement:

    > 3) The data to write must not be queued (no async)
    > 4) I want to detect disconnections with the server
    > 5) Like the writing is done in a thread i would like to not use signals
    > (no intr)
    >
    > I have put the following options to mount :
    > timeo=10,retrans=1,fg,soft,udp,sync but when i disconnect the server


    If you are using Solaris add forcedirectio to the list.

    > (deactivate NFS server), the write function on the file on the NFS
    > shared folder returns alternatively error and successful operation (the
    > function returns the number of bytes to write). It also returns
    > approximatively after one minute (I want to control this time ...).


    That's odd. At retrans=1,timeo=10, I would expect it to
    return after 10 + 2*10 = 30 tenths of a second.

    >
    > For example the following program returns alternatively OK 7 and KO
    > altough the server is not accessible
    > fd = open(DEST "/TEST.log", O_CREAT|O_WRONLY|O_TRUNC|O_SYNC);


    If you are using Linux, and are willing to add open flags,
    add O_DIRECT (or is it O_DIRECTIO) to the list.

    Either forcedirectio or O_DIRECT[IO] will force writes to
    be synchronous.

    The other thing you can do is issue fsync() after each
    write().


  3. Re: NFS and soft mount

    Thanks for your answer Mike,

    I'm using a linux client. Using TCP instead of UDP resolves my problem
    :
    After a disconnection the function returns in few seconds, and it
    returns always false while we are not connected again. It is OK for
    that but, the flow rate is too bad : about 20 MBit/s on a 100MBit/s
    networks. The problem comes from the sync option, if I replace it by
    async, the flow rate is about 90 ~100 MBit/s but all my problems come
    back

    > > 2) The "write" function must not be "blocking"

    > Not much you can do about that, especially considering
    > your next requirement:

    I'm sorry, I have not been clear for this requirement : When i sayed
    not "blocking", it is only when we cannot write ==> don't wait for ever
    (soft option)

    > Do you also want to know the data has not been written?

    Yes I want to know if the data has been written or not

    > That's odd. At retrans=1,timeo=10, I would expect it to
    > return after 10 + 2*10 = 30 tenths of a second.

    Yes that's odd. But TCP resolves this (i don't test if it is exactly 3
    seconds with TCP)

    > If you are using Linux, and are willing to add open flags,
    > add O_DIRECT (or is it O_DIRECTIO) to the list.

    I will try this flag (O_DIRECT but it seems to me that this option do
    not compile).

    Thanks
    Rezaa

    Mike Eisler wrote:

    > Rezaa wrote:
    > > Hi,
    > >
    > > I want to make an application that writes files on an NFS shared
    > > folder, but :
    > > 1) I want to know if the data has been successfully written

    >
    > Do you also want to know the data has not been written?
    >
    > > 2) The "write" function must not be "blocking"

    >
    > Not much you can do about that, especially considering
    > your next requirement:
    >
    > > 3) The data to write must not be queued (no async)
    > > 4) I want to detect disconnections with the server
    > > 5) Like the writing is done in a thread i would like to not use signals
    > > (no intr)
    > >
    > > I have put the following options to mount :
    > > timeo=10,retrans=1,fg,soft,udp,sync but when i disconnect the server

    >
    > If you are using Solaris add forcedirectio to the list.
    >
    > > (deactivate NFS server), the write function on the file on the NFS
    > > shared folder returns alternatively error and successful operation (the
    > > function returns the number of bytes to write). It also returns
    > > approximatively after one minute (I want to control this time ...).

    >
    > That's odd. At retrans=1,timeo=10, I would expect it to
    > return after 10 + 2*10 = 30 tenths of a second.
    >
    > >
    > > For example the following program returns alternatively OK 7 and KO
    > > altough the server is not accessible
    > > fd = open(DEST "/TEST.log", O_CREAT|O_WRONLY|O_TRUNC|O_SYNC);

    >
    > If you are using Linux, and are willing to add open flags,
    > add O_DIRECT (or is it O_DIRECTIO) to the list.
    >
    > Either forcedirectio or O_DIRECT[IO] will force writes to
    > be synchronous.
    >
    > The other thing you can do is issue fsync() after each
    > write().



  4. Re: NFS and soft mount


    Rezaa wrote:

    > > Do you also want to know the data has not been written?

    > Yes I want to know if the data has been written or not


    If you send a write, and timeout, you don't know
    if the data was written or not. With hard mounts
    you know definitively if if succeeded.

    >
    > > That's odd. At retrans=1,timeo=10, I would expect it to
    > > return after 10 + 2*10 = 30 tenths of a second.

    > Yes that's odd. But TCP resolves this (i don't test if it is exactly 3
    > seconds with TCP)


    3 seconds is going to be hard on your server if your attempted
    data rate is high.


+ Reply to Thread