qemu-virto9p: Implement TLOCK
PATCH 1/2 qemu-virto9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]Description
Tlock is used to acquire/release byte range posix locks on a file identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK(1) - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM(2) - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start' through to the end of file
pid[4] - PID of the process that wants to take lock client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful P9_LOCK_BLOCKED - A conflicting lock is held by another process P9_LOCK_ERROR - Error while processing the lock request P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with P9_LOCK_FLAGS_RECLAIM flag set)
--- hw/virtio-9p-debug.c | 14 ++++++++++++++ hw/virtio-9p.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 0 deletions(-)
hw/virtio-9p-debug.c +14 -0
@@ -588,6 +588,20 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RXATTRCREATE :fprintf (llogfile,"RXATTRCREATE: (" );break ; +case P9_TLOCK : +fprintf (llogfile,"TLOCK: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_int8 (pdu,0 , &offset,", type" ); +pprint_int32 (pdu,0 , &offset,", flags" ); +pprint_int64 (pdu,0 , &offset,", start" ); +pprint_int64 (pdu,0 , &offset,", length" ); +pprint_int32 (pdu,0 , &offset,", proc_id" ); +pprint_str (pdu,0 , &offset,", client_id" ); +break ; +case P9_RLOCK : +fprintf (llogfile,"RLOCK: (" ); +pprint_int8 (pdu,0 , &offset,"status" ); +break ;default :fprintf (llogfile,"unknown(%d): (" , pdu->id);break ;
hw/virtio-9p.c +50 -0
62 lines not on this page · raw message
hw/virtio-9p.h +30 -0
@@ -37,6 +37,8 @@ enum {P9_RXATTRCREATE ,P9_TREADDIR =40 ,P9_RREADDIR , +P9_TLOCK =52 , +P9_RLOCK ,P9_TLINK =70 ,P9_RLINK , P9_TMKDIR = 72,
@@ -434,6 +436,34 @@ typedef struct V9fsXattrStatevoid *value; } V9fsXattrState; +#define P9_LOCK_SUCCESS 0 +#define P9_LOCK_BLOCKED 1 +#define P9_LOCK_ERROR 2 +#define P9_LOCK_GRACE 3 + +#define P9_LOCK_FLAGS_BLOCK 1 +#define P9_LOCK_FLAGS_RECLAIM 2 + +typedef struct V9fsFlock +{ +uint8_t type; +uint32_t flags; +uint64_t start;/* absolute offset */ +uint64_t length; +uint32_t proc_id; +V9fsString client_id; +}V9fsFlock ; + +typedef struct V9fsLockState +{ +V9fsPDU *pdu; +size_t offset; +int8_t status; +struct stat stbuf; +V9fsFidState *fidp; +V9fsFlock *flock; +}V9fsLockState ; +extern size_t pdu_packunpack (void *addr,struct iovec *sg,int sg_count,size_t offset,size_t size,int pack);
Signature · 1 line
1.7.0.4