提交 c41d13a3 编写于 作者: I Ilya Dryomov

rbd: use header_oid instead of header_name

Switch to ceph_object_id and use ceph_oid_aprintf() instead of a bare
const char *.  This reduces noise in rbd_dev_header_name().
Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
上级 d30291b9
...@@ -350,7 +350,7 @@ struct rbd_device { ...@@ -350,7 +350,7 @@ struct rbd_device {
struct rbd_spec *spec; struct rbd_spec *spec;
struct rbd_options *opts; struct rbd_options *opts;
char *header_name; struct ceph_object_id header_oid;
struct ceph_file_layout layout; struct ceph_file_layout layout;
...@@ -3117,7 +3117,7 @@ static int rbd_obj_notify_ack_sync(struct rbd_device *rbd_dev, u64 notify_id) ...@@ -3117,7 +3117,7 @@ static int rbd_obj_notify_ack_sync(struct rbd_device *rbd_dev, u64 notify_id)
struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
int ret; int ret;
obj_request = rbd_obj_request_create(rbd_dev->header_name, 0, 0, obj_request = rbd_obj_request_create(rbd_dev->header_oid.name, 0, 0,
OBJ_REQUEST_NODATA); OBJ_REQUEST_NODATA);
if (!obj_request) if (!obj_request)
return -ENOMEM; return -ENOMEM;
...@@ -3148,7 +3148,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data) ...@@ -3148,7 +3148,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data)
int ret; int ret;
dout("%s: \"%s\" notify_id %llu opcode %u\n", __func__, dout("%s: \"%s\" notify_id %llu opcode %u\n", __func__,
rbd_dev->header_name, (unsigned long long)notify_id, rbd_dev->header_oid.name, (unsigned long long)notify_id,
(unsigned int)opcode); (unsigned int)opcode);
/* /*
...@@ -3179,7 +3179,7 @@ static struct rbd_obj_request *rbd_obj_watch_request_helper( ...@@ -3179,7 +3179,7 @@ static struct rbd_obj_request *rbd_obj_watch_request_helper(
struct rbd_obj_request *obj_request; struct rbd_obj_request *obj_request;
int ret; int ret;
obj_request = rbd_obj_request_create(rbd_dev->header_name, 0, 0, obj_request = rbd_obj_request_create(rbd_dev->header_oid.name, 0, 0,
OBJ_REQUEST_NODATA); OBJ_REQUEST_NODATA);
if (!obj_request) if (!obj_request)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -3612,7 +3612,7 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev) ...@@ -3612,7 +3612,7 @@ static int rbd_dev_v1_header_info(struct rbd_device *rbd_dev)
if (!ondisk) if (!ondisk)
return -ENOMEM; return -ENOMEM;
ret = rbd_obj_read_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_read_sync(rbd_dev, rbd_dev->header_oid.name,
0, size, ondisk); 0, size, ondisk);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -4054,6 +4054,8 @@ static void rbd_dev_release(struct device *dev) ...@@ -4054,6 +4054,8 @@ static void rbd_dev_release(struct device *dev)
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
bool need_put = !!rbd_dev->opts; bool need_put = !!rbd_dev->opts;
ceph_oid_destroy(&rbd_dev->header_oid);
rbd_put_client(rbd_dev->rbd_client); rbd_put_client(rbd_dev->rbd_client);
rbd_spec_put(rbd_dev->spec); rbd_spec_put(rbd_dev->spec);
kfree(rbd_dev->opts); kfree(rbd_dev->opts);
...@@ -4084,6 +4086,8 @@ static struct rbd_device *rbd_dev_create(struct rbd_client *rbdc, ...@@ -4084,6 +4086,8 @@ static struct rbd_device *rbd_dev_create(struct rbd_client *rbdc,
INIT_LIST_HEAD(&rbd_dev->node); INIT_LIST_HEAD(&rbd_dev->node);
init_rwsem(&rbd_dev->header_rwsem); init_rwsem(&rbd_dev->header_rwsem);
ceph_oid_init(&rbd_dev->header_oid);
rbd_dev->dev.bus = &rbd_bus_type; rbd_dev->dev.bus = &rbd_bus_type;
rbd_dev->dev.type = &rbd_device_type; rbd_dev->dev.type = &rbd_device_type;
rbd_dev->dev.parent = &rbd_root_dev; rbd_dev->dev.parent = &rbd_root_dev;
...@@ -4132,7 +4136,7 @@ static int _rbd_dev_v2_snap_size(struct rbd_device *rbd_dev, u64 snap_id, ...@@ -4132,7 +4136,7 @@ static int _rbd_dev_v2_snap_size(struct rbd_device *rbd_dev, u64 snap_id,
__le64 size; __le64 size;
} __attribute__ ((packed)) size_buf = { 0 }; } __attribute__ ((packed)) size_buf = { 0 };
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_size", "rbd", "get_size",
&snapid, sizeof (snapid), &snapid, sizeof (snapid),
&size_buf, sizeof (size_buf)); &size_buf, sizeof (size_buf));
...@@ -4172,7 +4176,7 @@ static int rbd_dev_v2_object_prefix(struct rbd_device *rbd_dev) ...@@ -4172,7 +4176,7 @@ static int rbd_dev_v2_object_prefix(struct rbd_device *rbd_dev)
if (!reply_buf) if (!reply_buf)
return -ENOMEM; return -ENOMEM;
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_object_prefix", NULL, 0, "rbd", "get_object_prefix", NULL, 0,
reply_buf, RBD_OBJ_PREFIX_LEN_MAX); reply_buf, RBD_OBJ_PREFIX_LEN_MAX);
dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret); dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret);
...@@ -4207,7 +4211,7 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, ...@@ -4207,7 +4211,7 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id,
u64 unsup; u64 unsup;
int ret; int ret;
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_features", "rbd", "get_features",
&snapid, sizeof (snapid), &snapid, sizeof (snapid),
&features_buf, sizeof (features_buf)); &features_buf, sizeof (features_buf));
...@@ -4269,7 +4273,7 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) ...@@ -4269,7 +4273,7 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
} }
snapid = cpu_to_le64(rbd_dev->spec->snap_id); snapid = cpu_to_le64(rbd_dev->spec->snap_id);
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_parent", "rbd", "get_parent",
&snapid, sizeof (snapid), &snapid, sizeof (snapid),
reply_buf, size); reply_buf, size);
...@@ -4372,7 +4376,7 @@ static int rbd_dev_v2_striping_info(struct rbd_device *rbd_dev) ...@@ -4372,7 +4376,7 @@ static int rbd_dev_v2_striping_info(struct rbd_device *rbd_dev)
u64 stripe_count; u64 stripe_count;
int ret; int ret;
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_stripe_unit_count", NULL, 0, "rbd", "get_stripe_unit_count", NULL, 0,
(char *)&striping_info_buf, size); (char *)&striping_info_buf, size);
dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret); dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret);
...@@ -4620,7 +4624,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev) ...@@ -4620,7 +4624,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev)
if (!reply_buf) if (!reply_buf)
return -ENOMEM; return -ENOMEM;
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_snapcontext", NULL, 0, "rbd", "get_snapcontext", NULL, 0,
reply_buf, size); reply_buf, size);
dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret); dout("%s: rbd_obj_method_sync returned %d\n", __func__, ret);
...@@ -4685,7 +4689,7 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, ...@@ -4685,7 +4689,7 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
snapid = cpu_to_le64(snap_id); snapid = cpu_to_le64(snap_id);
ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_oid.name,
"rbd", "get_snapshot_name", "rbd", "get_snapshot_name",
&snapid, sizeof (snapid), &snapid, sizeof (snapid),
reply_buf, size); reply_buf, size);
...@@ -5281,35 +5285,25 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev) ...@@ -5281,35 +5285,25 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)
static int rbd_dev_header_name(struct rbd_device *rbd_dev) static int rbd_dev_header_name(struct rbd_device *rbd_dev)
{ {
struct rbd_spec *spec = rbd_dev->spec; struct rbd_spec *spec = rbd_dev->spec;
size_t size; int ret;
/* Record the header object name for this rbd image. */ /* Record the header object name for this rbd image. */
rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); rbd_assert(rbd_image_format_valid(rbd_dev->image_format));
if (rbd_dev->image_format == 1) if (rbd_dev->image_format == 1)
size = strlen(spec->image_name) + sizeof (RBD_SUFFIX); ret = ceph_oid_aprintf(&rbd_dev->header_oid, GFP_KERNEL, "%s%s",
spec->image_name, RBD_SUFFIX);
else else
size = sizeof (RBD_HEADER_PREFIX) + strlen(spec->image_id); ret = ceph_oid_aprintf(&rbd_dev->header_oid, GFP_KERNEL, "%s%s",
RBD_HEADER_PREFIX, spec->image_id);
rbd_dev->header_name = kmalloc(size, GFP_KERNEL);
if (!rbd_dev->header_name)
return -ENOMEM;
if (rbd_dev->image_format == 1) return ret;
sprintf(rbd_dev->header_name, "%s%s",
spec->image_name, RBD_SUFFIX);
else
sprintf(rbd_dev->header_name, "%s%s",
RBD_HEADER_PREFIX, spec->image_id);
return 0;
} }
static void rbd_dev_image_release(struct rbd_device *rbd_dev) static void rbd_dev_image_release(struct rbd_device *rbd_dev)
{ {
rbd_dev_unprobe(rbd_dev); rbd_dev_unprobe(rbd_dev);
kfree(rbd_dev->header_name);
rbd_dev->header_name = NULL;
rbd_dev->image_format = 0; rbd_dev->image_format = 0;
kfree(rbd_dev->spec->image_id); kfree(rbd_dev->spec->image_id);
rbd_dev->spec->image_id = NULL; rbd_dev->spec->image_id = NULL;
...@@ -5348,7 +5342,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) ...@@ -5348,7 +5342,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
pr_info("image %s/%s does not exist\n", pr_info("image %s/%s does not exist\n",
rbd_dev->spec->pool_name, rbd_dev->spec->pool_name,
rbd_dev->spec->image_name); rbd_dev->spec->image_name);
goto out_header_name; goto err_out_format;
} }
} }
...@@ -5394,7 +5388,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) ...@@ -5394,7 +5388,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
goto err_out_probe; goto err_out_probe;
dout("discovered format %u image, header name is %s\n", dout("discovered format %u image, header name is %s\n",
rbd_dev->image_format, rbd_dev->header_name); rbd_dev->image_format, rbd_dev->header_oid.name);
return 0; return 0;
err_out_probe: err_out_probe:
...@@ -5402,9 +5396,6 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth) ...@@ -5402,9 +5396,6 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
err_out_watch: err_out_watch:
if (!depth) if (!depth)
rbd_dev_header_unwatch_sync(rbd_dev); rbd_dev_header_unwatch_sync(rbd_dev);
out_header_name:
kfree(rbd_dev->header_name);
rbd_dev->header_name = NULL;
err_out_format: err_out_format:
rbd_dev->image_format = 0; rbd_dev->image_format = 0;
kfree(rbd_dev->spec->image_id); kfree(rbd_dev->spec->image_id);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册