Commit d63b77f4 authored by Sage Weil's avatar Sage Weil Committed by Alex Elder

libceph: check for invalid mapping

If we encounter an invalid (e.g., zeroed) mapping, return an error
and avoid a divide by zero.
Signed-off-by: default avatarSage Weil <sage@inktank.com>
Reviewed-by: default avatarAlex Elder <elder@inktank.com>
parent b905a7f8
...@@ -207,7 +207,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc, ...@@ -207,7 +207,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc, extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
struct ceph_msg *msg); struct ceph_msg *msg);
extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc, extern int ceph_calc_raw_layout(struct ceph_osd_client *osdc,
struct ceph_file_layout *layout, struct ceph_file_layout *layout,
u64 snapid, u64 snapid,
u64 off, u64 *plen, u64 *bno, u64 off, u64 *plen, u64 *bno,
......
...@@ -109,7 +109,7 @@ extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, ...@@ -109,7 +109,7 @@ extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
extern void ceph_osdmap_destroy(struct ceph_osdmap *map); extern void ceph_osdmap_destroy(struct ceph_osdmap *map);
/* calculate mapping of a file extent to an object */ /* calculate mapping of a file extent to an object */
extern void ceph_calc_file_object_mapping(struct ceph_file_layout *layout, extern int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
u64 off, u64 *plen, u64 off, u64 *plen,
u64 *bno, u64 *oxoff, u64 *oxlen); u64 *bno, u64 *oxoff, u64 *oxlen);
......
...@@ -52,7 +52,7 @@ static int op_has_extent(int op) ...@@ -52,7 +52,7 @@ static int op_has_extent(int op)
op == CEPH_OSD_OP_WRITE); op == CEPH_OSD_OP_WRITE);
} }
void ceph_calc_raw_layout(struct ceph_osd_client *osdc, int ceph_calc_raw_layout(struct ceph_osd_client *osdc,
struct ceph_file_layout *layout, struct ceph_file_layout *layout,
u64 snapid, u64 snapid,
u64 off, u64 *plen, u64 *bno, u64 off, u64 *plen, u64 *bno,
...@@ -62,12 +62,15 @@ void ceph_calc_raw_layout(struct ceph_osd_client *osdc, ...@@ -62,12 +62,15 @@ void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
u64 orig_len = *plen; u64 orig_len = *plen;
u64 objoff, objlen; /* extent in object */ u64 objoff, objlen; /* extent in object */
int r;
reqhead->snapid = cpu_to_le64(snapid); reqhead->snapid = cpu_to_le64(snapid);
/* object extent? */ /* object extent? */
ceph_calc_file_object_mapping(layout, off, plen, bno, r = ceph_calc_file_object_mapping(layout, off, plen, bno,
&objoff, &objlen); &objoff, &objlen);
if (r < 0)
return r;
if (*plen < orig_len) if (*plen < orig_len)
dout(" skipping last %llu, final file extent %llu~%llu\n", dout(" skipping last %llu, final file extent %llu~%llu\n",
orig_len - *plen, off, *plen); orig_len - *plen, off, *plen);
...@@ -83,7 +86,7 @@ void ceph_calc_raw_layout(struct ceph_osd_client *osdc, ...@@ -83,7 +86,7 @@ void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
dout("calc_layout bno=%llx %llu~%llu (%d pages)\n", dout("calc_layout bno=%llx %llu~%llu (%d pages)\n",
*bno, objoff, objlen, req->r_num_pages); *bno, objoff, objlen, req->r_num_pages);
return 0;
} }
EXPORT_SYMBOL(ceph_calc_raw_layout); EXPORT_SYMBOL(ceph_calc_raw_layout);
...@@ -112,7 +115,7 @@ EXPORT_SYMBOL(ceph_calc_raw_layout); ...@@ -112,7 +115,7 @@ EXPORT_SYMBOL(ceph_calc_raw_layout);
* *
* fill osd op in request message. * fill osd op in request message.
*/ */
static void calc_layout(struct ceph_osd_client *osdc, static int calc_layout(struct ceph_osd_client *osdc,
struct ceph_vino vino, struct ceph_vino vino,
struct ceph_file_layout *layout, struct ceph_file_layout *layout,
u64 off, u64 *plen, u64 off, u64 *plen,
...@@ -120,12 +123,17 @@ static void calc_layout(struct ceph_osd_client *osdc, ...@@ -120,12 +123,17 @@ static void calc_layout(struct ceph_osd_client *osdc,
struct ceph_osd_req_op *op) struct ceph_osd_req_op *op)
{ {
u64 bno; u64 bno;
int r;
ceph_calc_raw_layout(osdc, layout, vino.snap, off, r = ceph_calc_raw_layout(osdc, layout, vino.snap, off,
plen, &bno, req, op); plen, &bno, req, op);
if (r < 0)
return r;
snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno); snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno);
req->r_oid_len = strlen(req->r_oid); req->r_oid_len = strlen(req->r_oid);
return r;
} }
/* /*
......
...@@ -984,7 +984,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, ...@@ -984,7 +984,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
* for now, we write only a single su, until we can * for now, we write only a single su, until we can
* pass a stride back to the caller. * pass a stride back to the caller.
*/ */
void ceph_calc_file_object_mapping(struct ceph_file_layout *layout, int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
u64 off, u64 *plen, u64 off, u64 *plen,
u64 *ono, u64 *ono,
u64 *oxoff, u64 *oxlen) u64 *oxoff, u64 *oxlen)
...@@ -998,11 +998,17 @@ void ceph_calc_file_object_mapping(struct ceph_file_layout *layout, ...@@ -998,11 +998,17 @@ void ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
dout("mapping %llu~%llu osize %u fl_su %u\n", off, *plen, dout("mapping %llu~%llu osize %u fl_su %u\n", off, *plen,
osize, su); osize, su);
if (su == 0 || sc == 0)
goto invalid;
su_per_object = osize / su; su_per_object = osize / su;
if (su_per_object == 0)
goto invalid;
dout("osize %u / su %u = su_per_object %u\n", osize, su, dout("osize %u / su %u = su_per_object %u\n", osize, su,
su_per_object); su_per_object);
BUG_ON((su & ~PAGE_MASK) != 0); if ((su & ~PAGE_MASK) != 0)
goto invalid;
/* bl = *off / su; */ /* bl = *off / su; */
t = off; t = off;
do_div(t, su); do_div(t, su);
...@@ -1030,6 +1036,14 @@ void ceph_calc_file_object_mapping(struct ceph_file_layout *layout, ...@@ -1030,6 +1036,14 @@ void ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
*plen = *oxlen; *plen = *oxlen;
dout(" obj extent %llu~%llu\n", *oxoff, *oxlen); dout(" obj extent %llu~%llu\n", *oxoff, *oxlen);
return 0;
invalid:
dout(" invalid layout\n");
*ono = 0;
*oxoff = 0;
*oxlen = 0;
return -EINVAL;
} }
EXPORT_SYMBOL(ceph_calc_file_object_mapping); EXPORT_SYMBOL(ceph_calc_file_object_mapping);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment