lustreapi(3)

NAME
llapi_file_open, llapi_file_create - open and possibly create a file or a device on a Lustre filesystem

SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <lustre/lustreapi.h>

int llapi_file_open(const char *name, int flags, int mode,
                    unsigned long long stripe_size, int stripe_offset,
                    int stripe_count, int stripe_pattern);
int llapi_file_create(const char *name, unsigned long long stripe_size,
                      int stripe_offset, int stripe_count,
                      int stripe_pattern);

DESCRIPTION

llapi_file_create() call is equivalent to llapi_file_open call with flags equal to O_CREAT|O_WRONLY and mode equal to 0644, followed by file close.

llapi_file_open() opens a file with a given name on a Lustre filesystem.

flags
    can be a combination of O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, O_NONBLOCK, O_SYNC, FASYNC, O_DIRECT, O_LARGEFILE, O_DIRECTORY, O_NOFOLLOW, O_NOATIME. Refer to open(2) man page for a detailed description.

mode
    specifies the permission bits to be used for a new file when O_CREAT is used. Refer to open(2) man page for a detailed description.

stripe_size
    specifies stripe size in bytes and should be multiple of 64 KiB not exceeding 4 GiB.

stripe_offset
    specifies an OST index from which the file should start, -1 to use the default setting.

stripe_count
    specifies number of OSTs to stripe the file across, -1 to use the default setting.

stripe_pattern
    specifies striping pattern, only LOV_PATTERN_RAID0 is available in this Lustre version, 0 to use the default setting.

RETURN VALUES

llapi_file_open() and llapi_file_create() return:

>=0 on success, for llapi_file_open the return value is a file descriptor.

<0  on failure, the absolute value is an error code.

ERRORS

EINVAL
    stripe_size or stripe_offset or stripe_count or stripe_pattern is invalid.

EEXIST
    Striping information has already been set and cannot be altered.

    name already exists.

EALREADY
    Striping information has already been set and cannot be altered.

ENOTTY
    name may not point to a Lustre filesystem.

EXAMPLE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <lustre/lustreapi.h>
int main(int argc, char *argv[])
{
        int rc;
        if (argc != 2)
                return -1;
        rc = llapi_file_create(argv[1], 1048576, 0, 2, LOV_PATTERN_RAID0);
        if (rc < 0) {
                fprintf(stderr, "file creation has failed, %s\n", strerror(-rc));
                return -1;
        }
        printf("%s with stripe size 1048576, striped across 2 OSTs,"
               " has been created!\n", argv[1]);
        return 0;
}

SEE ALSO
open(2), lustre(7), lustreapi(7)