[lustre-discuss] Hole Identification in file

Dilger, Andreas andreas.dilger at intel.com
Fri Mar 9 00:42:43 PST 2018


On Mar 6, 2018, at 00:12, lokesh jaliminche <lokesh.jaliminche at gmail.com> wrote:
> 
> Hi,
> 
> Does lustre support SEEK_HOLE/SEEK_DATA flag for lseek?
> 
> I did some experiment with the below program to find out if lustre supports SEEK_HOLE and SEEK_DATA flag. I found that lustre always returns the end of the file for SEEK_HOLE and 0 for SEEK_DATA and as per the man page this is the simplest implementation that file system can have(If they dont want to support these flags). So just wanted to confirm. 

Lustre does not directly support the SEEK_HOLE/SEEK_DATA interface currently.
What you are seeing is the default/minimum implementation provided by the
lseek interface.

Implementing these seek options might be quite complex for a Lustre file
because of multiple stripes in the layout.  You would need to locate holes
in the stripes, and then map the hole offset on the object to the file offset.

If this is something you are interested to implement I would be happy to
discuss it with you further.  Probably the best place to start is to file
an LU ticket with details, and then interested parties can discuss the
implementation there.

Cheers, Andreas

> Program :
> ========
> #include <unistd.h>
> #include <sys/types.h>
> #include <stdio.h>
> #include <fcntl.h>
> #include <stdlib.h>
> #define SEEK_OFF 10485760
> int main()
> {
>     int fd; 
>     char buffer[80];
>     int i = 0;
>     static char message[]="Hello world";
>     fd=open("myfile", O_RDWR);
>     if (fd != -1) 
>         return 1;
>     printf("creating hole by writing at each of %d strides\n", SEEK_OFF);
>     for (i = 1; i < 10; i++)
>     {   
>         int seek_off = i * SEEK_OFF;
>         int sz; 
>         printf("seek_off %ld\n", lseek(fd, seek_off, SEEK_SET));
>         sz = write(fd,message,sizeof(message));
>         printf("write size = %d\n", sz);
>         printf("String : %s\n", message);
>     }   
>     printf("Demonstrating SEEK_HOLE and SEEK_DATA %d \n", SEEK_OFF);
>     int start_off = 0;
>     lseek(fd, 0, SEEK_SET);
>     printf("after SEEK_HOLE start_off %ld\n", lseek(fd, 0, SEEK_HOLE));
>     printf("after SEEK_DATA start_off %ld\n", lseek(fd, start_off, SEEK_DATA));
>     printf("after SEEK_HOLE start_off %ld\n", lseek(fd, 10485760, SEEK_HOLE));
>     printf("after SEEK_DATA start_off %ld\n", lseek(fd, (10485760 *2 ), SEEK_DATA));
>     close(fd);
> }
> 
> output:
> =====
> after SEEK_HOLE start_off 94372142
> after SEEK_DATA start_off 0
> after SEEK_HOLE start_off 94372142
> after SEEK_DATA start_off 0
> 
> Regards,
> Lokesh
> _______________________________________________
> lustre-discuss mailing list
> lustre-discuss at lists.lustre.org
> http://lists.lustre.org/listinfo.cgi/lustre-discuss-lustre.org

Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation









More information about the lustre-discuss mailing list