Menu

#12 lutimes for symlink file failed with "Stale file handle"

Future
open
nobody
None
2018-06-28
2018-06-13
Rui Wang
No

I am not sure if this is a bug. I found if I try to modify the timestamp of a symlink file pointing to a none existence file with lutimes(), the program will get an error: Stale file handle. But if the symlink file points to an exist file, the operation will success. I found this in yocto nfsroot. And I write a simple program to reproduce the issue.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>

int main()
{
        int rc; 
        struct timeval stamps[2] = { 
                {.tv_sec = 0, .tv_usec = 0}, 
                {.tv_sec = 0, .tv_usec = 0}, 
        };


        printf("create symlink file test -> target\n");
        rc = symlink("target", "test");
        if (rc)
                perror("symlink");

        printf("**** target file is not exist ****\n");
        rc = lutimes("test", stamps);
        if (rc)
                perror("lutimes test");
        else
                printf("lutimes test success\n");

        system("touch target");

        printf("**** target file is exist ****\n");
        rc = lutimes("test", stamps);
        if (rc)
                perror("lutimes test");
        else
                printf("lutimes test success\n");

        system("rm test target");
        return 0;
}

Discussion

  • Karl Mikaelsson

    Karl Mikaelsson - 2018-06-13

    Hi and thanks for the report! I will try to find time for looking into this problem later this week.

     
    • Rui Wang

      Rui Wang - 2018-06-14

      Thanks for reply.

      I did some research and I think I have found something.

      The function set_time() in attr.c use function utime() to change the timestamp of a file. When the target is a symlink file, utime() will follow the symlink, and if the symlink points to a non-existent file, utime() will return -1. I made a work around for my condition, but the patch code still has some limitation: the code can not determine if the nfs client wants to modify the symlink file itself or to follow the symlink and modify the real file.

      I would apperciate it if you have any suggestion about the patch code. If you think the code will not bring any bug to unfs3, I will use this work round for now.

       
  • Karl Mikaelsson

    Karl Mikaelsson - 2018-06-28

    Sorry for not getting back to you earlier - I've been swamped with other things at work. I just wanted to say that I haven't forgotten about this yet. The bad news is that I'll be away on vacation for almost a month, but I hope to get back to this when I return.

     
MongoDB Logo MongoDB