<div dir="ltr">Reviewed-by: Robin Dong <<a href="mailto:sanbai@taobao.com">sanbai@taobao.com</a>></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014/1/9 Liu Yuan <span dir="ltr"><<a href="mailto:namei.unix@gmail.com" target="_blank">namei.unix@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We should return how many bytes actually written/read from vdi. This fixes a<br>
bug that cat sheepfs/volume/vdi never return.<br>
<br>
Signed-off-by: Liu Yuan <<a href="mailto:namei.unix@gmail.com">namei.unix@gmail.com</a>><br>
---<br>
sheepfs/volume.c | 32 ++++++++++++++++++++++++--------<br>
1 file changed, 24 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/sheepfs/volume.c b/sheepfs/volume.c<br>
index f6aadaf..f862c4a 100644<br>
--- a/sheepfs/volume.c<br>
+++ b/sheepfs/volume.c<br>
@@ -207,18 +207,29 @@ done:<br>
}<br>
<br>
/* Do sync read/write */<br>
-static int volume_do_rw(const char *path, char *buf, size_t size,<br>
- off_t offset, int rw)<br>
+static ssize_t volume_do_rw(const char *path, char *buf, size_t size,<br>
+ off_t offset, int rw)<br>
{<br>
uint32_t vid;<br>
uint64_t oid;<br>
unsigned long idx;<br>
off_t start;<br>
- size_t len, ret;<br>
+ size_t len, ret, vdi_size, sz;<br>
<br>
if (shadow_file_getxattr(path, SH_VID_NAME, &vid, SH_VID_SIZE) < 0)<br>
return -1;<br>
<br>
+ if (shadow_file_getxattr(path, SH_SIZE_NAME, &vdi_size, SH_SIZE_SIZE)<br>
+ < 0)<br>
+ return -1;<br>
+<br>
+ if (offset >= vdi_size)<br>
+ return 0;<br>
+<br>
+ if (offset + size > vdi_size)<br>
+ size = vdi_size - offset;<br>
+<br>
+ sz = size;<br>
idx = offset / SD_DATA_OBJ_SIZE;<br>
oid = vid_to_data_oid(vid, idx);<br>
start = offset % SD_DATA_OBJ_SIZE;<br>
@@ -246,7 +257,7 @@ static int volume_do_rw(const char *path, char *buf, size_t size,<br>
len = size > SD_DATA_OBJ_SIZE ? SD_DATA_OBJ_SIZE : size;<br>
} while (size > 0);<br>
<br>
- return 0;<br>
+ return sz - size;<br>
}<br>
<br>
int sheepfs_bnode_writer(uint64_t oid, void *mem, unsigned int len,<br>
@@ -272,19 +283,24 @@ int sheepfs_bnode_reader(uint64_t oid, void **mem, unsigned int len,<br>
<br>
int volume_read(const char *path, char *buf, size_t size, off_t offset)<br>
{<br>
+ ssize_t done;<br>
<br>
- if (volume_do_rw(path, buf, size, offset, VOLUME_READ) < 0)<br>
+ done = volume_do_rw(path, buf, size, offset, VOLUME_READ);<br>
+ if (done < 0)<br>
return -EIO;<br>
<br>
- return size;<br>
+ return done;<br>
}<br>
<br>
int volume_write(const char *path, const char *buf, size_t size, off_t offset)<br>
{<br>
- if (volume_do_rw(path, (char *)buf, size, offset, VOLUME_WRITE) < 0)<br>
+ ssize_t done;<br>
+<br>
+ done = volume_do_rw(path, (char *)buf, size, offset, VOLUME_WRITE);<br>
+ if (done < 0)<br>
return -EIO;<br>
<br>
- return size;<br>
+ return done;<br>
}<br>
<br>
size_t volume_get_size(const char *path)<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
--<br>
sheepdog mailing list<br>
<a href="mailto:sheepdog@lists.wpkg.org">sheepdog@lists.wpkg.org</a><br>
<a href="http://lists.wpkg.org/mailman/listinfo/sheepdog" target="_blank">http://lists.wpkg.org/mailman/listinfo/sheepdog</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Best Regard<br>Robin Dong
</div>