
Defining file stripe patterns 6–3
6.1.2 Using a C program to create a file
The following C program fragment shows an example of how to create a file with a defined stripe pattern;
the program also determines that the file system is a Lustre file system.
Example 6-1 C program fragment—creating a file with a defined stripe pattern
# include <stdlib.h>
# include <limits.h>
# include <li/jointfilesconvert/261981/bgen.h>
# include <stdio.h>
# include <sys/vfs.h>
# include <lustre/liblustreapi.h>
# include <linux/lustre_idl.h>
int stripe_size=1024*1024*8; /* 8MB - different from HP StorageWorks SFS */
/* V2.2-0 default stripe size of 4MB */
int stripe_offset=-1; /* default start OST */
int stripe_count=2; /* stripe count of 2 */
int main(int argc, char *argv[])
{
struct statfs statbuf;
int sts;
char *dirpath;
char *filename;
if (argc != 2) {
fprintf(stderr, "Usage: stripefile <file_path>\n");
exit(EXIT_FAILURE);
}
filename = argv[1];
dirpath = strdup(filename);
dirpath = dirname(dirpath);
sts = statfs(dirpath,statbuf);
if (sts < 0)
{
perror ("statfs");
fprintf(stderr, "directory path %s\n", dirpath);
exit(EXIT_FAILURE);
}
if (statbuf.f_type == LOV_MAGIC_V0 || statbuf.f_type == LOV_MAGIC_V1)
{
printf("It’s a lustre fileystem\n");
if (llapi_file_create(filename, stripe_size, stripe_offset,
stripe_count, 0))
{
fprintf(stderr, "striping failure\n");
exit(EXIT_FAILURE);
}
}
else
{
fprintf(stderr, "%s (f_type 0x%x) is not a lustre File System\n",
dirpath, statbuf.f_type);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
To compile the program, enter the following command:
$ gcc -o /tmp/stripefile -g /tmp/stripefile.c -llustreapi
Komentáře k této Příručce