Skip to content

Commit

Permalink
osd-target: Fix an sg_read BUG when one of the segments is short
Browse files Browse the repository at this point in the history
In OSD it is not an error to read passed EOF. Zeros are put and
the read should continue to the next segments. When done if the
total read was short a warrning is issued as stated.

Also better debug prints when sg_read bales out on errors.

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
  • Loading branch information
Boaz Harrosh committed Feb 11, 2011
1 parent e9e8792 commit 2a99ef6
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions osd-target/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,11 +3002,16 @@ static int sgl_read(struct osd_device *osd, uint64_t pid, uint64_t oid,

osd_debug("%s: ------------------------------", __func__);
ret = pread(fd, outdata+data_offset, length, offset_val+offset);
data_offset += length;
osd_debug("%s: return value is %d", __func__, ret);
if (ret < 0 || (uint64_t)ret != length)
if (ret < 0)
goto out_hw_err;
readlen += ret;
if ((size_t) ret < length) {
/* valid, fill with zeros */
memset(outdata+data_offset+ret, 0, length - ret);
length = ret;
}
data_offset += length;
readlen += length;
}

ret = close(fd);
Expand Down Expand Up @@ -3479,21 +3484,30 @@ int osd_set_attributes(struct osd_device *osd, uint64_t pid, uint64_t oid,
assert(osd && osd->root && osd->dbc && sense);

ret = obj_ispresent(osd->dbc, pid, oid, &present);
if (ret != OSD_OK || !present) /* object not present! */
if (ret != OSD_OK || !present) {/* object not present! */
osd_warning("%s: object not present pid %llu oid %llu", __func__,
llu(pid), llu(oid));
goto out_cdb_err;
}

obj_type = get_obj_type(osd, pid, oid);
if (obj_type == ILLEGAL_OBJ)
if (obj_type == ILLEGAL_OBJ) {
osd_warning("%s: !get_obj_type pid %llu oid %llu", __func__,
llu(pid), llu(oid));
goto out_cdb_err;
}

if (issettable_page(obj_type, page) == false)
goto out_param_list;

if (number == ATTRNUM_UNMODIFIABLE)
goto out_param_list;

if ((val == NULL && len != 0) || (val != NULL && len == 0))
if ((val == NULL && len != 0) || (val != NULL && len == 0)) {
osd_warning("%s: NULLs %llu oid %llu", __func__,
llu(pid), llu(oid));
goto out_cdb_err;
}

/* information page, make sure null terminated. osd2r00 7.1.2.2 */
if (number == ATTRNUM_INFO) {
Expand All @@ -3506,8 +3520,11 @@ int osd_set_attributes(struct osd_device *osd, uint64_t pid, uint64_t oid,
if (s[i] == 0)
break;
}
if (i == len)
if (i == len) {
osd_warning("%s: !null terminated %llu oid %llu",
__func__, llu(pid), llu(oid));
goto out_cdb_err;
}
}

if (len > ATTR_LEN_UB)
Expand Down

0 comments on commit 2a99ef6

Please sign in to comment.