Skip to content

Commit 51b8b4f

Browse files
garlickericvh
authored andcommitted
fs/9p: Use protocol-defined value for lock/getlock 'type' field.
Signed-off-by: Jim Garlick <[email protected]> Signed-off-by: Aneesh Kumar K.V <[email protected]>
1 parent 73f5071 commit 51b8b4f

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

fs/9p/vfs_file.c

+27-7
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,18 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl)
169169

170170
/* convert posix lock to p9 tlock args */
171171
memset(&flock, 0, sizeof(flock));
172-
flock.type = fl->fl_type;
172+
/* map the lock type */
173+
switch (fl->fl_type) {
174+
case F_RDLCK:
175+
flock.type = P9_LOCK_TYPE_RDLCK;
176+
break;
177+
case F_WRLCK:
178+
flock.type = P9_LOCK_TYPE_WRLCK;
179+
break;
180+
case F_UNLCK:
181+
flock.type = P9_LOCK_TYPE_UNLCK;
182+
break;
183+
}
173184
flock.start = fl->fl_start;
174185
if (fl->fl_end == OFFSET_MAX)
175186
flock.length = 0;
@@ -245,7 +256,7 @@ static int v9fs_file_getlock(struct file *filp, struct file_lock *fl)
245256

246257
/* convert posix lock to p9 tgetlock args */
247258
memset(&glock, 0, sizeof(glock));
248-
glock.type = fl->fl_type;
259+
glock.type = P9_LOCK_TYPE_UNLCK;
249260
glock.start = fl->fl_start;
250261
if (fl->fl_end == OFFSET_MAX)
251262
glock.length = 0;
@@ -257,17 +268,26 @@ static int v9fs_file_getlock(struct file *filp, struct file_lock *fl)
257268
res = p9_client_getlock_dotl(fid, &glock);
258269
if (res < 0)
259270
return res;
260-
if (glock.type != F_UNLCK) {
261-
fl->fl_type = glock.type;
271+
/* map 9p lock type to os lock type */
272+
switch (glock.type) {
273+
case P9_LOCK_TYPE_RDLCK:
274+
fl->fl_type = F_RDLCK;
275+
break;
276+
case P9_LOCK_TYPE_WRLCK:
277+
fl->fl_type = F_WRLCK;
278+
break;
279+
case P9_LOCK_TYPE_UNLCK:
280+
fl->fl_type = F_UNLCK;
281+
break;
282+
}
283+
if (glock.type != P9_LOCK_TYPE_UNLCK) {
262284
fl->fl_start = glock.start;
263285
if (glock.length == 0)
264286
fl->fl_end = OFFSET_MAX;
265287
else
266288
fl->fl_end = glock.start + glock.length - 1;
267289
fl->fl_pid = glock.proc_id;
268-
} else
269-
fl->fl_type = F_UNLCK;
270-
290+
}
271291
return res;
272292
}
273293

include/net/9p/9p.h

+5
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ enum p9_perm_t {
312312
/* 9p2000.L at flags */
313313
#define P9_DOTL_AT_REMOVEDIR 0x200
314314

315+
/* 9p2000.L lock type */
316+
#define P9_LOCK_TYPE_RDLCK 0
317+
#define P9_LOCK_TYPE_WRLCK 1
318+
#define P9_LOCK_TYPE_UNLCK 2
319+
315320
/**
316321
* enum p9_qid_t - QID types
317322
* @P9_QTDIR: directory

0 commit comments

Comments
 (0)