int llapi_json_write_list(struct llapi_json_item_list **item_list, FILE *fp);
/* File lease */
-int llapi_lease_get(int fd, int mode);
+int llapi_lease_acquire(int fd, enum ll_lease_mode mode);
+int llapi_lease_release(int fd);
+int llapi_lease_set(int fd, const struct ll_ioc_lease *data);
int llapi_lease_check(int fd);
-int llapi_lease_put(int fd);
-extern int llapi_lease_get_ext(int fd, struct ll_ioc_lease *data);
+int llapi_lease_get(int fd, int mode); /* obsoleted */
+int llapi_lease_put(int fd); /* obsoleted */
/* Group lock */
int llapi_group_lock(int fd, int gid);
enum ll_lease_flags {
LL_LEASE_RESYNC = 0x1,
LL_LEASE_RESYNC_DONE = 0x2,
+ LL_LEASE_LAYOUT_MERGE = 0x4,
};
#define IOC_IDS_MAX 4096
#define SWAP_LAYOUTS_KEEP_MTIME (1 << 2)
#define SWAP_LAYOUTS_KEEP_ATIME (1 << 3)
#define SWAP_LAYOUTS_CLOSE (1 << 4)
-#define MERGE_LAYOUTS_CLOSE (1 << 5)
-#define INTENT_LAYOUTS_CLOSE (SWAP_LAYOUTS_CLOSE | MERGE_LAYOUTS_CLOSE)
/* Swap XATTR_NAME_HSM as well, only on the MDT so far */
#define SWAP_LAYOUTS_MDS_HSM (1 << 31)
}
static int ll_swap_layouts_close(struct obd_client_handle *och,
- struct inode *inode, struct inode *inode2,
- int intent)
+ struct inode *inode, struct inode *inode2)
{
const struct lu_fid *fid1 = ll_inode2fid(inode);
const struct lu_fid *fid2;
- enum mds_op_bias bias;
int rc;
ENTRY;
if (rc == 0)
GOTO(out_free_och, rc = -EINVAL);
- switch (intent) {
- case SWAP_LAYOUTS_CLOSE:
- bias = MDS_CLOSE_LAYOUT_SWAP;
- break;
- case MERGE_LAYOUTS_CLOSE:
- bias = MDS_CLOSE_LAYOUT_MERGE;
- break;
- default:
- GOTO(out_free_och, rc = -EOPNOTSUPP);
- }
-
/* Close the file and {swap,merge} layouts between inode & inode2.
* NB: lease lock handle is released in mdc_close_layout_swap_pack()
* because we still need it to pack l_remote_handle to MDT. */
- rc = ll_close_inode_openhandle(inode, och, bias, inode2);
+ rc = ll_close_inode_openhandle(inode, och, MDS_CLOSE_LAYOUT_SWAP,
+ inode2);
och = NULL; /* freed in ll_close_inode_openhandle() */
bool lease_broken;
fmode_t fmode = 0;
enum mds_op_bias bias = 0;
+ struct file *layout_file = NULL;
void *data = NULL;
size_t data_size = 0;
long rc;
fmode = och->och_flags;
- if (ioc->lil_flags & LL_LEASE_RESYNC_DONE) {
+ switch (ioc->lil_flags) {
+ case LL_LEASE_RESYNC_DONE:
if (ioc->lil_count > IOC_IDS_MAX)
GOTO(out, rc = -EINVAL);
GOTO(out, rc = -EFAULT);
bias = MDS_CLOSE_RESYNC_DONE;
+ break;
+ case LL_LEASE_LAYOUT_MERGE: {
+ int fd;
+
+ if (ioc->lil_count != 1)
+ GOTO(out, rc = -EINVAL);
+
+ arg += sizeof(*ioc);
+ if (copy_from_user(&fd, (void __user *)arg, sizeof(__u32)))
+ GOTO(out, rc = -EFAULT);
+
+ layout_file = fget(fd);
+ if (!layout_file)
+ GOTO(out, rc = -EBADF);
+
+ if ((file->f_flags & O_ACCMODE) == O_RDONLY ||
+ (layout_file->f_flags & O_ACCMODE) == O_RDONLY)
+ GOTO(out, rc = -EPERM);
+
+ data = file_inode(layout_file);
+ bias = MDS_CLOSE_LAYOUT_MERGE;
+ break;
+ }
+ default:
+ /* without close intent */
+ break;
}
rc = ll_lease_close_intent(och, inode, &lease_broken, bias, data);
EXIT;
out:
- if (data)
- OBD_FREE(data, data_size);
+ switch (ioc->lil_flags) {
+ case LL_LEASE_RESYNC_DONE:
+ if (data)
+ OBD_FREE(data, data_size);
+ break;
+ case LL_LEASE_LAYOUT_MERGE:
+ if (layout_file)
+ fput(layout_file);
+ break;
+ }
+
if (!rc)
rc = ll_lease_type_from_fmode(fmode);
RETURN(rc);
case LL_IOC_LOV_SWAP_LAYOUTS: {
struct file *file2;
struct lustre_swap_layouts lsl;
- __u64 intent;
if (copy_from_user(&lsl, (char __user *)arg,
sizeof(struct lustre_swap_layouts)))
if ((file2->f_flags & O_ACCMODE) == O_RDONLY)
GOTO(out, rc = -EPERM);
- intent = lsl.sl_flags & INTENT_LAYOUTS_CLOSE;
- if (intent) {
+ if (lsl.sl_flags & SWAP_LAYOUTS_CLOSE) {
struct inode *inode2;
struct ll_inode_info *lli;
struct obd_client_handle *och = NULL;
if (och == NULL)
GOTO(out, rc = -ENOLCK);
inode2 = file_inode(file2);
- rc = ll_swap_layouts_close(och, inode, inode2, intent);
+ rc = ll_swap_layouts_close(och, inode, inode2);
} else {
rc = ll_swap_layouts(file, file2, &lsl);
}
ioc->lil_mode = LL_LEASE_WRLCK;
ioc->lil_flags = LL_LEASE_RESYNC;
- rc = llapi_lease_get_ext(fd, ioc);
+ rc = llapi_lease_set(fd, ioc);
if (rc < 0)
free(ioc);
- syserr(rc < 0, "llapi_lease_get_ext resync");
+ syserr(rc < 0, "llapi_lease_set resync");
if (error_inject & AFTER_RESYNC_START) {
free(ioc);
if (error_inject & OPEN_TEST_FILE) /* break lease */
close(open(argv[optind], O_RDONLY));
- rc = llapi_lease_get_ext(fd, ioc);
- syserr(rc <= 0, "llapi_lease_get_ext resync failed");
+ rc = llapi_lease_set(fd, ioc);
+ syserr(rc <= 0, "llapi_lease_set resync failed");
free(ioc);
close(fd);
commands++;
switch (*commands) {
case 'U':
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
break;
case 'R':
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
break;
case 'W':
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
break;
default:
errx(-1, "unknown mode: %c", *commands);
fd = create_file("foo1", 1000, 'x');
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
fd = open(filename, O_RDONLY);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
fd = open(filename, O_WRONLY);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
fd = open(filename, O_WRONLY);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == -EPERM, "cannot get lease '%s': %s",
filename, strerror(-rc));
fd = open(filename, O_RDONLY);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == -EPERM, "cannot get lease '%s': %s",
filename, strerror(-rc));
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == -EBUSY, "can get lease '%s': %s",
filename, strerror(-rc));
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == -EBUSY, "can get lease '%s': %s",
filename, strerror(-rc));
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
ASSERTF(rc == LL_LEASE_RDLCK,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_RDLCK, "was not able to put back lease '%s': %s",
filename, strerror(-rc));
ASSERTF(rc == 0,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
ASSERTF(rc == LL_LEASE_WRLCK,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_WRLCK, "was not able to put back lease '%s': %s",
filename, strerror(-rc));
ASSERTF(rc == 0,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
for (i = 0; i < 1000; i++) {
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s",
filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_WRLCK,
"was not able to put back lease '%s': %s",
filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s",
filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_RDLCK,
"was not able to put back lease '%s': %s",
filename, strerror(-rc));
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
ASSERTF(rc == LL_LEASE_WRLCK,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_WRLCK, "was not able to put back lease '%s': %s",
filename, strerror(-rc));
ASSERTF(rc == 0,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
fd = open(filename, O_RDWR);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
rc = llapi_lease_check(fd);
ASSERTF(rc == LL_LEASE_RDLCK,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_put(fd);
+ rc = llapi_lease_release(fd);
ASSERTF(rc == LL_LEASE_RDLCK, "was not able to put back lease '%s': %s",
filename, strerror(-rc));
ASSERTF(rc == 0,
"invalid lease type on '%s': %s", filename, strerror(-rc));
- rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_WRLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
O_RDWR | O_NOATIME | O_NONBLOCK | O_NOFOLLOW);
ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
close(fd);
fd = open(mainpath, O_DIRECTORY);
ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == -ENOTTY, "can get lease on directory '%s': %s",
mainpath, strerror(-rc));
fd = open(fsmountdir, O_DIRECTORY);
ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno));
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
ASSERTF(rc == -ENOTTY, "can get lease on directory '%s': %s",
mainpath, strerror(-rc));
fd1 = create_file("foo1", foo1_size, 'x');
fd2 = create_file("foo2", foo2_size, 'y');
- rc = llapi_lease_get(fd1, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd1, LL_LEASE_RDLCK);
ASSERTF(rc == 0, "cannot get lease '%s': %s", mainpath, strerror(-rc));
rc = llapi_lease_check(fd1);
rc = llapi_lease_check(fd1);
ASSERTF(rc == 0, "lease not lost on '%s': %s", mainpath, strerror(-rc));
- rc = llapi_lease_put(fd1);
+ rc = llapi_lease_release(fd1);
ASSERTF(rc == -ENOLCK,
"was able to put back lease: %s", strerror(-rc));
goto out;
}
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
if (rc < 0) {
error_loc = "cannot get lease";
goto out;
rc = migrate_nonblock(fd, fdv);
if (rc < 0) {
- llapi_lease_put(fd);
+ llapi_lease_release(fd);
goto out;
}
/* Atomically put lease, swap layouts and close.
* for a migration we need to check data version on file did
* not change. */
- rc = llapi_fswap_layouts(fd, fdv, 0, 0,
- migration_flags & MIGRATION_MIRROR ?
- MERGE_LAYOUTS_CLOSE : SWAP_LAYOUTS_CLOSE);
+ rc = llapi_fswap_layouts(fd, fdv, 0, 0, SWAP_LAYOUTS_CLOSE);
if (rc < 0) {
error_loc = "cannot swap layout";
goto out;
int fdv = -1;
struct stat stbuf;
struct stat stbuf_v;
+ struct ll_ioc_lease *data = NULL;
int rc;
fd = open(fname, O_RDWR);
goto out;
}
- rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
if (rc < 0) {
error_loc = "cannot get lease";
goto out;
goto out;
}
- /* Atomically put lease, swap layouts and close.
- * for a migration we need to check data version on file did
- * not change. */
- rc = llapi_fswap_layouts(fd, fdv, 0, 0, MERGE_LAYOUTS_CLOSE);
+ /* Atomically put lease, merge layouts and close. */
+ data = calloc(1, offsetof(typeof(*data), lil_ids[1]));
+ if (!data) {
+ error_loc = "memory allocation";
+ goto out;
+ }
+ data->lil_mode = LL_LEASE_UNLCK;
+ data->lil_flags = LL_LEASE_LAYOUT_MERGE;
+ data->lil_count = 1;
+ data->lil_ids[0] = fdv;
+ rc = llapi_lease_set(fd, data);
if (rc < 0) {
- error_loc = "cannot swap layout";
+ error_loc = "cannot merge layout";
+ goto out;
+ } else if (rc == 0) {
+ rc = -EBUSY;
+ error_loc = "lost lease lock";
goto out;
}
+ rc = 0;
out:
+ if (data)
+ free(data);
if (fd >= 0)
close(fd);
-
if (fdv >= 0)
close(fdv);
-
if (!rc)
(void) unlink(victim_file);
-
if (rc < 0)
fprintf(stderr, "error: %s: %s: %s: %s\n",
progname, fname, error_loc, strerror(-rc));
return rc;
}
+static int mirror_extend_layout(char *name, struct llapi_layout *layout)
+{
+ struct ll_ioc_lease *data = NULL;
+ int fd = -1;
+ int fdv = -1;
+ int rc;
+
+ rc = migrate_open_files(name, NULL, layout, &fd, &fdv);
+ if (rc < 0)
+ goto out;
+
+ rc = llapi_lease_acquire(fd, LL_LEASE_RDLCK);
+ if (rc < 0) {
+ error_loc = "cannot get lease";
+ goto out;
+ }
+
+ rc = migrate_nonblock(fd, fdv);
+ if (rc < 0) {
+ llapi_lease_release(fd);
+ goto out;
+ }
+
+ /* Atomically put lease, merge layouts and close. */
+ data = calloc(1, offsetof(typeof(*data), lil_ids[1]));
+ if (!data) {
+ error_loc = "memory allocation";
+ goto out;
+ }
+ data->lil_mode = LL_LEASE_UNLCK;
+ data->lil_flags = LL_LEASE_LAYOUT_MERGE;
+ data->lil_count = 1;
+ data->lil_ids[0] = fdv;
+ rc = llapi_lease_set(fd, data);
+ if (rc < 0) {
+ error_loc = "cannot merge layout";
+ goto out;
+ } else if (rc == 0) {
+ rc = -EBUSY;
+ error_loc = "lost lease lock";
+ goto out;
+ }
+ rc = 0;
+
+out:
+ if (data)
+ free(data);
+ if (fd >= 0)
+ close(fd);
+ if (fdv >= 0)
+ close(fdv);
+ if (rc < 0)
+ fprintf(stderr, "error: %s: %s: %s: %s\n",
+ progname, name, error_loc, strerror(-rc));
+ return rc;
+}
+
static int mirror_extend(char *fname, struct mirror_args *mirror_list,
enum mirror_flags mirror_flags)
{
__u32 mirror_count = mirror_list->m_count;
while (mirror_count > 0) {
- rc = lfs_migrate(fname,
- MIGRATION_NONBLOCK | MIGRATION_MIRROR,
- NULL, mirror_list->m_layout);
+ rc = mirror_extend_layout(fname,
+ mirror_list->m_layout);
if (rc)
break;
ioc->lil_mode = LL_LEASE_WRLCK;
ioc->lil_flags = LL_LEASE_RESYNC;
- rc = llapi_lease_get_ext(fd, ioc);
+ rc = llapi_lease_set(fd, ioc);
if (rc < 0) {
- fprintf(stderr, "%s: '%s' llapi_lease_get_ext resync failed: "
+ fprintf(stderr, "%s: '%s' llapi_lease_set resync failed: "
"%s.\n", progname, fname, strerror(errno));
goto close_fd;
}
llapi_layout_free(layout);
- rc = llapi_lease_get_ext(fd, ioc);
+ rc = llapi_lease_set(fd, ioc);
if (rc <= 0) {
if (rc == 0) /* lost lease lock */
rc = -EBUSY;
goto close_fd;
}
/**
- * llapi_lease_get_ext returns lease mode when it request to unlock
+ * llapi_lease_set returns lease mode when it request to unlock
* the lease lock
*/
rc = 0;
#include <lustre/lustreapi.h>
#include "lustreapi_internal.h"
-static inline const char *lease_mode2str(int mode)
+static inline const char *lease_mode2str(enum ll_lease_mode mode)
{
switch (mode) {
case LL_LEASE_WRLCK: return "WRITE";
}
/**
- * Extend lease get support.
+ * Extend lease set support.
*
- * \param fd File to get lease on.
+ * \param fd File to set lease on.
* \param data ll_ioc_lease data.
*
- * For getting lease lock, it will return zero for success. For unlock, it will
+ * For setting lease lock, it will return zero for success. For unlock, it will
* return the lock type it owned for succuess.
*
* \retval >= 0 on success.
* \retval -errno on error.
*/
-int llapi_lease_get_ext(int fd, struct ll_ioc_lease *data)
+int llapi_lease_set(int fd, const struct ll_ioc_lease *data)
{
int rc;
if (rc < 0) {
rc = -errno;
- /* exclude ENOTTY in case this is an old kernel that only
- * supports LL_IOC_SET_LEASE_OLD */
- if (rc != -ENOTTY)
- llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot get %s lease, ext %x",
- lease_mode2str(data->lil_mode),
- data->lil_flags);
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot get %s lease, ext %x",
+ lease_mode2str(data->lil_mode), data->lil_flags);
}
return rc;
}
/**
- * Get a lease on an open file.
+ * Acquire a lease on an open file.
*
* \param fd File to get the lease on.
* \param mode Lease mode, either LL_LEASE_RDLCK or LL_LEASE_WRLCK.
*
- * \see llapi_lease_get_ext().
+ * \see llapi_lease_release().
*
* \retval >= 0 on success.
* \retval -errno on error.
*/
-int llapi_lease_get(int fd, int mode)
+int llapi_lease_acquire(int fd, enum ll_lease_mode mode)
{
- struct ll_ioc_lease data = { 0 };
+ struct ll_ioc_lease data = { .lil_mode = mode };
int rc;
if (mode != LL_LEASE_RDLCK && mode != LL_LEASE_WRLCK)
return -EINVAL;
- data.lil_mode = mode;
- rc = llapi_lease_get_ext(fd, &data);
+ rc = llapi_lease_set(fd, &data);
if (rc == -ENOTTY) {
rc = ioctl(fd, LL_IOC_SET_LEASE_OLD, mode);
if (rc < 0)
}
/**
+ * Release a lease.
+ *
+ * \param fd File to remove the lease from.
+ *
+ * \retval type of the lease that was removed (LL_LEASE_READ or LL_LEASE_WRITE).
+ * \retval 0 if no lease was present.
+ * \retval -errno on error.
+ */
+int llapi_lease_release(int fd)
+{
+ struct ll_ioc_lease data = { .lil_mode = LL_LEASE_UNLCK };
+
+ return llapi_lease_set(fd, &data);
+}
+
+/**
+ * Release a lease with intent operation. This API will release the lease
+ * and execute the intent operation atomically.
+ *
+ * \param fd File to remove the lease from.
+ *
+ * \retval type of the lease that was removed (LL_LEASE_READ or LL_LEASE_WRITE).
+ * \retval 0 if no lease was present.
+ * \retval -EBUSY lease broken, intent operation not executed.
+ * \retval -errno on error.
+ */
+int llapi_lease_release_intent(int fd, struct ll_ioc_lease *data)
+{
+ if (data->lil_mode != LL_LEASE_UNLCK)
+ return -EINVAL;
+
+ return llapi_lease_set(fd, data);
+}
+
+/**
* Check if a lease is still set on a file.
*
* \param fd File to check the lease on.
}
/**
- * Remove a lease.
- *
- * \param fd File to remove the lease from.
- *
- * \retval type of the lease that was removed (LL_LEASE_READ or LL_LEASE_WRITE).
- * \retval 0 if no lease was present.
- * \retval -errno on error.
+ * XXX: This is an obsoleted API - do not use it any more.
+ */
+int llapi_lease_get(int fd, int mode)
+{
+ int rc;
+
+ if (mode != LL_LEASE_RDLCK && mode != LL_LEASE_WRLCK)
+ return -EINVAL;
+
+ rc = ioctl(fd, LL_IOC_SET_LEASE_OLD, mode);
+ if (rc < 0)
+ rc = -errno;
+
+ return rc;
+}
+
+/**
+ * XXX: This is an obsoleted API - do not use it any more.
*/
int llapi_lease_put(int fd)
{
- struct ll_ioc_lease data = { .lil_mode = LL_LEASE_UNLCK };
+ int rc;
- return llapi_lease_get_ext(fd, &data);
+ rc = ioctl(fd, LL_IOC_SET_LEASE_OLD, LL_LEASE_UNLCK);
+ if (rc < 0)
+ rc = -errno;
+
+ return rc;
}