From: levin li <[email protected]>

We should lock the object when read it in read_working_object
just as we did in farm_read

Signed-off-by: levin li <[email protected]>
---
 sheep/farm/farm.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 9e05e12..8169991 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -376,15 +376,27 @@ static void *read_working_object(uint64_t oid, uint64_t 
offset,
                goto out;
        }
 
+       if (flock(fd, LOCK_SH) < 0) {
+               eprintf("%m\n");
+               goto err;
+       }
+
        size = xpread(fd, buf, length, offset);
+       if (flock(fd, LOCK_UN) < 0) {
+               eprintf("%m\n");
+               goto err;
+       }
+
        if (length != size) {
                eprintf("size %zu len %"PRIu32" off %"PRIu64" %m\n", size,
                        length, offset);
-               free(buf);
-               buf = NULL;
-               goto out;
+               goto err;
        }
+       goto out;
 
+err:
+       free(buf);
+       buf = NULL;
 out:
        if (fd > 0)
                close(fd);
-- 
1.7.1

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to