diff options
author | Herb Shiu <herb_shiu@tcloudcomputing.com> | 2010-11-23 16:42:23 -0500 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2010-12-01 17:22:34 -0500 |
commit | 637ae8d547390df75bad42a7e9cb65e625119767 (patch) | |
tree | 311b5e454928e8954aee522d8c1a943954c9ea7e /fs/ceph | |
parent | 25933abdd8c562182ca6dc9f8c4c2cc8265c3a80 (diff) |
ceph: pass lock information by struct file_lock instead of as individual params.
Signed-off-by: Herb Shiu <herb_shiu@tcloudcomputing.com>
Acked-by: Greg Farnum <gregf@hq.newdream.net>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/locks.c | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c index 40abde93c345..7b7ac310f052 100644 --- a/fs/ceph/locks.c +++ b/fs/ceph/locks.c | |||
@@ -11,40 +11,49 @@ | |||
11 | * Implement fcntl and flock locking functions. | 11 | * Implement fcntl and flock locking functions. |
12 | */ | 12 | */ |
13 | static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, | 13 | static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, |
14 | u64 pid, u64 pid_ns, | 14 | int cmd, u8 wait, struct file_lock *fl) |
15 | int cmd, u64 start, u64 length, u8 wait) | ||
16 | { | 15 | { |
17 | struct inode *inode = file->f_dentry->d_inode; | 16 | struct inode *inode = file->f_dentry->d_inode; |
18 | struct ceph_mds_client *mdsc = | 17 | struct ceph_mds_client *mdsc = |
19 | ceph_sb_to_client(inode->i_sb)->mdsc; | 18 | ceph_sb_to_client(inode->i_sb)->mdsc; |
20 | struct ceph_mds_request *req; | 19 | struct ceph_mds_request *req; |
21 | int err; | 20 | int err; |
21 | u64 length = 0; | ||
22 | 22 | ||
23 | req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS); | 23 | req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS); |
24 | if (IS_ERR(req)) | 24 | if (IS_ERR(req)) |
25 | return PTR_ERR(req); | 25 | return PTR_ERR(req); |
26 | req->r_inode = igrab(inode); | 26 | req->r_inode = igrab(inode); |
27 | 27 | ||
28 | /* mds requires start and length rather than start and end */ | ||
29 | if (LLONG_MAX == fl->fl_end) | ||
30 | length = 0; | ||
31 | else | ||
32 | length = fl->fl_end - fl->fl_start + 1; | ||
33 | |||
28 | dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " | 34 | dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " |
29 | "length: %llu, wait: %d, type`: %d", (int)lock_type, | 35 | "length: %llu, wait: %d, type`: %d", (int)lock_type, |
30 | (int)operation, pid, start, length, wait, cmd); | 36 | (int)operation, (u64)fl->fl_pid, fl->fl_start, |
37 | length, wait, fl->fl_type); | ||
38 | |||
31 | 39 | ||
32 | req->r_args.filelock_change.rule = lock_type; | 40 | req->r_args.filelock_change.rule = lock_type; |
33 | req->r_args.filelock_change.type = cmd; | 41 | req->r_args.filelock_change.type = cmd; |
34 | req->r_args.filelock_change.pid = cpu_to_le64(pid); | 42 | req->r_args.filelock_change.pid = cpu_to_le64((u64)fl->fl_pid); |
35 | /* This should be adjusted, but I'm not sure if | 43 | /* This should be adjusted, but I'm not sure if |
36 | namespaces actually get id numbers*/ | 44 | namespaces actually get id numbers*/ |
37 | req->r_args.filelock_change.pid_namespace = | 45 | req->r_args.filelock_change.pid_namespace = |
38 | cpu_to_le64((u64)pid_ns); | 46 | cpu_to_le64((u64)(unsigned long)fl->fl_nspid); |
39 | req->r_args.filelock_change.start = cpu_to_le64(start); | 47 | req->r_args.filelock_change.start = cpu_to_le64(fl->fl_start); |
40 | req->r_args.filelock_change.length = cpu_to_le64(length); | 48 | req->r_args.filelock_change.length = cpu_to_le64(length); |
41 | req->r_args.filelock_change.wait = wait; | 49 | req->r_args.filelock_change.wait = wait; |
42 | 50 | ||
43 | err = ceph_mdsc_do_request(mdsc, inode, req); | 51 | err = ceph_mdsc_do_request(mdsc, inode, req); |
44 | ceph_mdsc_put_request(req); | 52 | ceph_mdsc_put_request(req); |
45 | dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " | 53 | dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, " |
46 | "length: %llu, wait: %d, type`: %d err code %d", (int)lock_type, | 54 | "length: %llu, wait: %d, type`: %d, err code %d", (int)lock_type, |
47 | (int)operation, pid, start, length, wait, cmd, err); | 55 | (int)operation, (u64)fl->fl_pid, fl->fl_start, |
56 | length, wait, fl->fl_type, err); | ||
48 | return err; | 57 | return err; |
49 | } | 58 | } |
50 | 59 | ||
@@ -54,7 +63,6 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file, | |||
54 | */ | 63 | */ |
55 | int ceph_lock(struct file *file, int cmd, struct file_lock *fl) | 64 | int ceph_lock(struct file *file, int cmd, struct file_lock *fl) |
56 | { | 65 | { |
57 | u64 length; | ||
58 | u8 lock_cmd; | 66 | u8 lock_cmd; |
59 | int err; | 67 | int err; |
60 | u8 wait = 0; | 68 | u8 wait = 0; |
@@ -76,16 +84,7 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) | |||
76 | else | 84 | else |
77 | lock_cmd = CEPH_LOCK_UNLOCK; | 85 | lock_cmd = CEPH_LOCK_UNLOCK; |
78 | 86 | ||
79 | if (LLONG_MAX == fl->fl_end) | 87 | err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, lock_cmd, wait, fl); |
80 | length = 0; | ||
81 | else | ||
82 | length = fl->fl_end - fl->fl_start + 1; | ||
83 | |||
84 | err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file, | ||
85 | (u64)fl->fl_pid, | ||
86 | (u64)(unsigned long)fl->fl_nspid, | ||
87 | lock_cmd, fl->fl_start, | ||
88 | length, wait); | ||
89 | if (!err) { | 88 | if (!err) { |
90 | dout("mds locked, locking locally"); | 89 | dout("mds locked, locking locally"); |
91 | err = posix_lock_file(file, fl, NULL); | 90 | err = posix_lock_file(file, fl, NULL); |
@@ -93,10 +92,7 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) | |||
93 | /* undo! This should only happen if the kernel detects | 92 | /* undo! This should only happen if the kernel detects |
94 | * local deadlock. */ | 93 | * local deadlock. */ |
95 | ceph_lock_message(CEPH_LOCK_FCNTL, op, file, | 94 | ceph_lock_message(CEPH_LOCK_FCNTL, op, file, |
96 | (u64)fl->fl_pid, | 95 | CEPH_LOCK_UNLOCK, 0, fl); |
97 | (u64)(unsigned long)fl->fl_nspid, | ||
98 | CEPH_LOCK_UNLOCK, fl->fl_start, | ||
99 | length, 0); | ||
100 | dout("got %d on posix_lock_file, undid lock", err); | 96 | dout("got %d on posix_lock_file, undid lock", err); |
101 | } | 97 | } |
102 | } else { | 98 | } else { |
@@ -107,7 +103,6 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) | |||
107 | 103 | ||
108 | int ceph_flock(struct file *file, int cmd, struct file_lock *fl) | 104 | int ceph_flock(struct file *file, int cmd, struct file_lock *fl) |
109 | { | 105 | { |
110 | u64 length; | ||
111 | u8 lock_cmd; | 106 | u8 lock_cmd; |
112 | int err; | 107 | int err; |
113 | u8 wait = 1; | 108 | u8 wait = 1; |
@@ -127,26 +122,15 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl) | |||
127 | lock_cmd = CEPH_LOCK_EXCL; | 122 | lock_cmd = CEPH_LOCK_EXCL; |
128 | else | 123 | else |
129 | lock_cmd = CEPH_LOCK_UNLOCK; | 124 | lock_cmd = CEPH_LOCK_UNLOCK; |
130 | /* mds requires start and length rather than start and end */ | ||
131 | if (LLONG_MAX == fl->fl_end) | ||
132 | length = 0; | ||
133 | else | ||
134 | length = fl->fl_end - fl->fl_start + 1; | ||
135 | 125 | ||
136 | err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, | 126 | err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, |
137 | file, (u64)fl->fl_pid, | 127 | file, lock_cmd, wait, fl); |
138 | (u64)(unsigned long)fl->fl_nspid, | ||
139 | lock_cmd, fl->fl_start, | ||
140 | length, wait); | ||
141 | if (!err) { | 128 | if (!err) { |
142 | err = flock_lock_file_wait(file, fl); | 129 | err = flock_lock_file_wait(file, fl); |
143 | if (err) { | 130 | if (err) { |
144 | ceph_lock_message(CEPH_LOCK_FLOCK, | 131 | ceph_lock_message(CEPH_LOCK_FLOCK, |
145 | CEPH_MDS_OP_SETFILELOCK, | 132 | CEPH_MDS_OP_SETFILELOCK, |
146 | file, (u64)fl->fl_pid, | 133 | file, CEPH_LOCK_UNLOCK, 0, fl); |
147 | (u64)(unsigned long)fl->fl_nspid, | ||
148 | CEPH_LOCK_UNLOCK, fl->fl_start, | ||
149 | length, 0); | ||
150 | dout("got %d on flock_lock_file_wait, undid lock", err); | 134 | dout("got %d on flock_lock_file_wait, undid lock", err); |
151 | } | 135 | } |
152 | } else { | 136 | } else { |