Commit 54daec18 authored by Andrei Vagin's avatar Andrei Vagin

test/file_locks: use struct flock instead of struct flock64

If we want to use flock64, we have to use fcntl64. Otherwise we will get
errors like this:
ERR: file_locks07.c:49: Can't set ofd lock (errno = 22 (Invalid argument))

Reported-by: Mr Jenkins
Signed-off-by: 's avatarAndrei Vagin <avagin@gmail.com>
parent e2bd7af9
...@@ -22,7 +22,7 @@ char file1[PATH_MAX]; ...@@ -22,7 +22,7 @@ char file1[PATH_MAX];
static int lock_reg(int fd, int cmd, int type, int whence, static int lock_reg(int fd, int cmd, int type, int whence,
off_t offset, off_t len) off_t offset, off_t len)
{ {
struct flock64 lock; struct flock lock;
lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */
lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
...@@ -40,7 +40,7 @@ static int lock_reg(int fd, int cmd, int type, int whence, ...@@ -40,7 +40,7 @@ static int lock_reg(int fd, int cmd, int type, int whence,
static int check_read_lock(int fd, int whence, off_t offset, off_t len) static int check_read_lock(int fd, int whence, off_t offset, off_t len)
{ {
struct flock64 lock; struct flock lock;
int ret; int ret;
lock.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
...@@ -67,7 +67,7 @@ static int check_read_lock(int fd, int whence, off_t offset, off_t len) ...@@ -67,7 +67,7 @@ static int check_read_lock(int fd, int whence, off_t offset, off_t len)
static int check_write_lock(int fd, int whence, off_t offset, off_t len) static int check_write_lock(int fd, int whence, off_t offset, off_t len)
{ {
struct flock64 lock; struct flock lock;
int ret; int ret;
pid_t ppid = getppid(); pid_t ppid = getppid();
......
...@@ -12,7 +12,7 @@ char *filename; ...@@ -12,7 +12,7 @@ char *filename;
TEST_OPTION(filename, string, "file name", 1); TEST_OPTION(filename, string, "file name", 1);
int init_lock(int *fd, struct flock64 *lck) int init_lock(int *fd, struct flock *lck)
{ {
*fd = open(filename, O_RDWR | O_CREAT, 0666); *fd = open(filename, O_RDWR | O_CREAT, 0666);
if (*fd < 0) { if (*fd < 0) {
...@@ -45,7 +45,7 @@ void cleanup(int *fd) ...@@ -45,7 +45,7 @@ void cleanup(int *fd)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd; int fd;
struct flock64 lck; struct flock lck;
test_init(argc, argv); test_init(argc, argv);
if (init_lock(&fd, &lck)) if (init_lock(&fd, &lck))
......
...@@ -14,12 +14,12 @@ TEST_OPTION(filename, string, "file name", 1); ...@@ -14,12 +14,12 @@ TEST_OPTION(filename, string, "file name", 1);
#define FILE_NUM 4 #define FILE_NUM 4
static int fds[FILE_NUM]; static int fds[FILE_NUM];
static struct flock64 lcks[FILE_NUM]; static struct flock lcks[FILE_NUM];
static short types[] = {F_RDLCK, F_RDLCK, F_RDLCK, F_RDLCK}; static short types[] = {F_RDLCK, F_RDLCK, F_RDLCK, F_RDLCK};
static off_t starts[] = {0, 10, 0, 70}; static off_t starts[] = {0, 10, 0, 70};
static off_t lens[] = {20, 30, 100, 200}; static off_t lens[] = {20, 30, 100, 200};
void fill_lock(struct flock64 *lock, off_t start, off_t len, short int type) void fill_lock(struct flock *lock, off_t start, off_t len, short int type)
{ {
lock->l_start = start; lock->l_start = start;
lock->l_len = len; lock->l_len = len;
......
...@@ -14,7 +14,7 @@ char *filename; ...@@ -14,7 +14,7 @@ char *filename;
TEST_OPTION(filename, string, "file name", 1); TEST_OPTION(filename, string, "file name", 1);
int init_file_lock(int *fd, struct flock64 *lck) int init_file_lock(int *fd, struct flock *lck)
{ {
*fd = open(filename, O_RDWR | O_CREAT, 0666); *fd = open(filename, O_RDWR | O_CREAT, 0666);
if (*fd < 0) { if (*fd < 0) {
...@@ -51,7 +51,7 @@ int main(int argc, char **argv) ...@@ -51,7 +51,7 @@ int main(int argc, char **argv)
int status; int status;
int ret = 0; int ret = 0;
task_waiter_t tw; task_waiter_t tw;
struct flock64 lck; struct flock lck;
test_init(argc, argv); test_init(argc, argv);
if (init_file_lock(&fd, &lck)) if (init_file_lock(&fd, &lck))
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "fs.h" #include "fs.h"
#include "ofd_file_locks.h" #include "ofd_file_locks.h"
static int parse_ofd_lock(char *buf, struct flock64 *lck) static int parse_ofd_lock(char *buf, struct flock *lck)
{ {
char fl_flag[10], fl_type[15], fl_option[10], fl_end[32]; char fl_flag[10], fl_type[15], fl_option[10], fl_end[32];
long long start; long long start;
...@@ -48,7 +48,7 @@ static int parse_ofd_lock(char *buf, struct flock64 *lck) ...@@ -48,7 +48,7 @@ static int parse_ofd_lock(char *buf, struct flock64 *lck)
return 0; return 0;
} }
static int read_fd_ofd_lock(int pid, int fd, struct flock64 *lck) static int read_fd_ofd_lock(int pid, int fd, struct flock *lck)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
char buf[100]; char buf[100];
...@@ -77,7 +77,7 @@ static int read_fd_ofd_lock(int pid, int fd, struct flock64 *lck) ...@@ -77,7 +77,7 @@ static int read_fd_ofd_lock(int pid, int fd, struct flock64 *lck)
return num; return num;
} }
int check_lock_exists(const char *filename, struct flock64 *lck) int check_lock_exists(const char *filename, struct flock *lck)
{ {
int ret = -1; int ret = -1;
int fd; int fd;
...@@ -116,16 +116,16 @@ out: ...@@ -116,16 +116,16 @@ out:
return ret; return ret;
} }
static int check_file_locks_match(struct flock64 *orig_lck, struct flock64 *lck) static int check_file_locks_match(struct flock *orig_lck, struct flock *lck)
{ {
return orig_lck->l_start == lck->l_start && return orig_lck->l_start == lck->l_start &&
orig_lck->l_len == lck->l_len && orig_lck->l_len == lck->l_len &&
orig_lck->l_type == lck->l_type; orig_lck->l_type == lck->l_type;
} }
int check_file_lock_restored(int pid, int fd, struct flock64 *lck) int check_file_lock_restored(int pid, int fd, struct flock *lck)
{ {
struct flock64 lck_restored; struct flock lck_restored;
if (read_fd_ofd_lock(pid, fd, &lck_restored)) if (read_fd_ofd_lock(pid, fd, &lck_restored))
return -1; return -1;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* from procfs and checking them after restoring. * from procfs and checking them after restoring.
*/ */
extern int check_lock_exists(const char *filename, struct flock64 *lck); extern int check_lock_exists(const char *filename, struct flock *lck);
extern int check_file_lock_restored(int pid, int fd, struct flock64 *lck); extern int check_file_lock_restored(int pid, int fd, struct flock *lck);
#endif /* ZDTM_OFD_FILE_LOCKS_H_ */ #endif /* ZDTM_OFD_FILE_LOCKS_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment