#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;
}