X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi_lease.c;h=60ad9bc8adc883162424698dfdd9565335532027;hb=0561c144cc1bb623e05d08b5055009e8d86047f4;hp=8869754311af2434e1998e899988253fc6599c99;hpb=ccabce23bd9e366c345c852f565766a799f61238;p=fs%2Flustre-release.git diff --git a/lustre/utils/liblustreapi_lease.c b/lustre/utils/liblustreapi_lease.c index 8869754..60ad9bc 100644 --- a/lustre/utils/liblustreapi_lease.c +++ b/lustre/utils/liblustreapi_lease.c @@ -36,7 +36,7 @@ #include #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"; @@ -47,18 +47,18 @@ static inline const char *lease_mode2str(int mode) } /** - * 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; @@ -66,38 +66,32 @@ int llapi_lease_get_ext(int fd, struct ll_ioc_lease *data) 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) @@ -108,6 +102,41 @@ int llapi_lease_get(int fd, int mode) } /** + * 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. @@ -129,17 +158,32 @@ int llapi_lease_check(int fd) } /** - * 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; }