[sheepdog] [PATCH 2/2] farm: drop fcntl lock

Liu Yuan namei.unix at gmail.com
Mon Jun 4 04:42:00 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

For a second thought, even QEMU can issue multiple requests to the same object
we are guaranteed that those requests don't overlap on each other. Recovery
code and IO code might access the same object, but the race is excluded by epoch
so we don't need per-object lock at all for now.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/farm/farm.c |   36 ------------------------------------
 1 file changed, 36 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 12a7d1a..323b086 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -109,7 +109,6 @@ static int farm_write(uint64_t oid, struct siocb *iocb, int create)
 	int flags = def_open_flags, fd, ret = SD_RES_SUCCESS;
 	char path[PATH_MAX];
 	ssize_t size;
-	struct flock fl;
 
 	if (iocb->epoch < sys_epoch()) {
 		dprintf("%"PRIu32" sys %"PRIu32"\n", iocb->epoch, sys_epoch());
@@ -126,18 +125,6 @@ static int farm_write(uint64_t oid, struct siocb *iocb, int create)
 	if (fd < 0)
 		return err_to_sderr(oid, errno);
 
-	fl.l_type = F_WRLCK;
-	fl.l_whence = SEEK_SET;
-	/* For create, we lock the whole object */
-	fl.l_start = create ? 0: iocb->offset;
-	fl.l_len = create ? (is_vdi_obj(oid) ? SD_INODE_SIZE : SD_DATA_OBJ_SIZE)
-		   : iocb->length;
-	fl.l_pid = getpid();
-	if (fcntl(fd, F_SETLKW, &fl) < 0) {
-		eprintf("%m\n");
-		ret = SD_RES_EIO;
-		goto out;
-	}
 	if (create && !(iocb->flags & SD_FLAG_CMD_COW)) {
 		ret = prealloc(fd, is_vdi_obj(oid) ?
 			       SD_INODE_SIZE : SD_DATA_OBJ_SIZE);
@@ -145,12 +132,6 @@ static int farm_write(uint64_t oid, struct siocb *iocb, int create)
 			goto out;
 	}
 	size = xpwrite(fd, iocb->buf, iocb->length, iocb->offset);
-	fl.l_type = F_UNLCK;
-	if (fcntl(fd, F_SETLK, &fl) < 0) {
-		ret = SD_RES_EIO;
-		eprintf("%m\n");
-		goto out;
-	}
 	if (size != iocb->length) {
 		eprintf("%m\n");
 		ret = SD_RES_EIO;
@@ -433,7 +414,6 @@ static int farm_read(uint64_t oid, struct siocb *iocb)
 	ssize_t size;
 	int i;
 	void *buffer;
-	struct flock fl;
 
 	if (iocb->epoch < epoch) {
 
@@ -471,23 +451,7 @@ static int farm_read(uint64_t oid, struct siocb *iocb)
 	if (fd < 0)
 		return err_to_sderr(oid, errno);
 
-	fl.l_type = F_RDLCK;
-	fl.l_whence = SEEK_SET;
-	fl.l_start = iocb->offset;
-	fl.l_len = iocb->length;
-	fl.l_pid = getpid();
-	if (fcntl(fd, F_SETLKW, &fl) < 0) {
-		eprintf("%m\n");
-		ret = SD_RES_EIO;
-		goto out;
-	}
 	size = xpread(fd, iocb->buf, iocb->length, iocb->offset);
-	fl.l_type = F_UNLCK;
-	if (fcntl(fd, F_SETLK, &fl) < 0) {
-		ret = SD_RES_EIO;
-		eprintf("%m\n");
-		goto out;
-	}
 	if (size != iocb->length) {
 		ret = SD_RES_EIO;
 		goto out;
-- 
1.7.10.2




More information about the sheepdog mailing list