Define new constants LL_LEASE_{RD,WR,UN}LCK for use as the argument to
and return value from the LL_IOC_{GET,SET}_LEASE ioctls. As arguments,
these contants replace the use of F_{RD,WR,UN}LCK from fcntl.h. As
return values they replace the use of FMODE_{READ,WRITE} which are
internal to the Linux kernel source and not under the control of the
Lustre ioctl interface.
Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I2643d7c548f84dd91cd2855894bf22f94fd20e98
Reviewed-on: http://review.whamcloud.com/10233
Tested-by: Jenkins
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
#define LL_IOC_MIGRATE _IOR('f', 247, int)
#define LL_IOC_FID2MDTIDX _IOWR('f', 248, struct lu_fid)
#define LL_IOC_MIGRATE _IOR('f', 247, int)
#define LL_IOC_FID2MDTIDX _IOWR('f', 248, struct lu_fid)
+/* Lease types for use as arg and return of LL_IOC_{GET,SET}_LEASE ioctl. */
+enum ll_lease_type {
+ LL_LEASE_RDLCK = 0x1,
+ LL_LEASE_WRLCK = 0x2,
+ LL_LEASE_UNLCK = 0x4,
+};
+
#define LL_STATFS_LMV 1
#define LL_STATFS_LOV 2
#define LL_STATFS_NODELAY 4
#define LL_STATFS_LMV 1
#define LL_STATFS_LOV 2
#define LL_STATFS_NODELAY 4
+static inline long ll_lease_type_from_fmode(fmode_t fmode)
+{
+ return ((fmode & FMODE_READ) ? LL_LEASE_RDLCK : 0) |
+ ((fmode & FMODE_WRITE) ? LL_LEASE_WRLCK : 0);
+}
+
static long
ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
static long
ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct ll_inode_info *lli = ll_i2info(inode);
struct obd_client_handle *och = NULL;
bool lease_broken;
struct ll_inode_info *lli = ll_i2info(inode);
struct obd_client_handle *och = NULL;
bool lease_broken;
if (!(file->f_mode & FMODE_WRITE))
RETURN(-EPERM);
if (!(file->f_mode & FMODE_WRITE))
RETURN(-EPERM);
if (!(file->f_mode & FMODE_READ))
RETURN(-EPERM);
if (!(file->f_mode & FMODE_READ))
RETURN(-EPERM);
mutex_lock(&lli->lli_och_mutex);
if (fd->fd_lease_och != NULL) {
och = fd->fd_lease_och;
mutex_lock(&lli->lli_och_mutex);
if (fd->fd_lease_och != NULL) {
och = fd->fd_lease_och;
}
mutex_unlock(&lli->lli_och_mutex);
}
mutex_unlock(&lli->lli_och_mutex);
- if (och != NULL) {
- mode = och->och_flags &(FMODE_READ|FMODE_WRITE);
- rc = ll_lease_close(och, inode, &lease_broken);
- if (rc == 0 && lease_broken)
- mode = 0;
- } else {
- rc = -ENOLCK;
- }
+ if (och == NULL)
+ RETURN(-ENOLCK);
+
+ fmode = och->och_flags;
+ rc = ll_lease_close(och, inode, &lease_broken);
+ if (rc < 0)
+ RETURN(rc);
+
+ if (lease_broken)
+ fmode = 0;
- /* return the type of lease or error */
- RETURN(rc < 0 ? rc : (int)mode);
+ RETURN(ll_lease_type_from_fmode(fmode));
default:
RETURN(-EINVAL);
}
default:
RETURN(-EINVAL);
}
- CDEBUG(D_INODE, "Set lease with mode %d\n", mode);
+ CDEBUG(D_INODE, "Set lease with mode %u\n", fmode);
- och = ll_lease_open(inode, file, mode, 0);
+ och = ll_lease_open(inode, file, fmode, 0);
if (IS_ERR(och))
RETURN(PTR_ERR(och));
if (IS_ERR(och))
RETURN(PTR_ERR(och));
case LL_IOC_GET_LEASE: {
struct ll_inode_info *lli = ll_i2info(inode);
struct ldlm_lock *lock = NULL;
case LL_IOC_GET_LEASE: {
struct ll_inode_info *lli = ll_i2info(inode);
struct ldlm_lock *lock = NULL;
mutex_lock(&lli->lli_och_mutex);
if (fd->fd_lease_och != NULL) {
struct obd_client_handle *och = fd->fd_lease_och;
mutex_lock(&lli->lli_och_mutex);
if (fd->fd_lease_och != NULL) {
struct obd_client_handle *och = fd->fd_lease_och;
if (lock != NULL) {
lock_res_and_lock(lock);
if (!ldlm_is_cancel(lock))
if (lock != NULL) {
lock_res_and_lock(lock);
if (!ldlm_is_cancel(lock))
- rc = och->och_flags &
- (FMODE_READ | FMODE_WRITE);
+ fmode = och->och_flags;
+
unlock_res_and_lock(lock);
LDLM_LOCK_PUT(lock);
}
}
mutex_unlock(&lli->lli_och_mutex);
unlock_res_and_lock(lock);
LDLM_LOCK_PUT(lock);
}
}
mutex_unlock(&lli->lli_och_mutex);
+
+ RETURN(ll_lease_type_from_fmode(fmode));
}
case LL_IOC_HSM_IMPORT: {
struct hsm_user_import *hui;
}
case LL_IOC_HSM_IMPORT: {
struct hsm_user_import *hui;
commands++;
switch (*commands) {
case 'U':
commands++;
switch (*commands) {
case 'U':
+ flags = LL_LEASE_UNLCK;
+ flags = LL_LEASE_RDLCK;
+ flags = LL_LEASE_WRLCK;
break;
default:
errx(-1, "unknown mode: %c", *commands);
break;
default:
errx(-1, "unknown mode: %c", *commands);
if (rc < 0)
err(errno, "apply lease error");
if (rc < 0)
err(errno, "apply lease error");
+ if (flags != LL_LEASE_UNLCK)
break;
/* F_UNLCK, interpret return code */
if (rc > 0) {
break;
/* F_UNLCK, interpret return code */
if (rc > 0) {
- const char *str = "Unknown";
- if (rc == FMODE_READ)
- str = "FMODE_READ";
- else if (rc == FMODE_WRITE)
- str = "FMODE_WRITE";
+ const char *str = "unknown";
+ if (rc == LL_LEASE_RDLCK)
+ str = "read";
+ else if (rc == LL_LEASE_WRLCK)
+ str = "write";
fprintf(stdout, "%s lease(%d) released.\n",
str, rc);
} else if (rc == 0) {
fprintf(stdout, "%s lease(%d) released.\n",
str, rc);
} else if (rc == 0) {
rc = ioctl(fd, LL_IOC_GET_LEASE);
if (rc > 0) {
rc = ioctl(fd, LL_IOC_GET_LEASE);
if (rc > 0) {
- const char *str = "Unknown";
+ const char *str = "unknown";
- if (rc == FMODE_READ)
- str = "FMODE_READ";
- else if (rc == FMODE_WRITE)
- str = "FMODE_WRITE";
+ if (rc == LL_LEASE_RDLCK)
+ str = "read";
+ else if (rc == LL_LEASE_WRLCK)
+ str = "write";
fprintf(stdout, "%s lease(%d) has applied.\n",
str, rc);
if (*commands == '-')
fprintf(stdout, "%s lease(%d) has applied.\n",
str, rc);
if (*commands == '-')