diff options
author | Josh Durgin <josh.durgin@dreamhost.com> | 2011-09-21 19:47:47 +0200 |
---|---|---|
committer | Josh Durgin <josh.durgin@dreamhost.com> | 2011-09-27 03:10:39 +0200 |
commit | bc16878cc5de5ef82e2f65a2f34485a87dfee8db (patch) | |
tree | a2a6c3ffcb9fcad06ceab4cd5439bbe00f2d422d | |
parent | rbd.py: add partial bindings for librbd (diff) | |
download | ceph-bc16878cc5de5ef82e2f65a2f34485a87dfee8db.tar.xz ceph-bc16878cc5de5ef82e2f65a2f34485a87dfee8db.zip |
Use cpp_strerror or strerror_r when appropriate.
The only remaining uses of strerror are in single-threaded programs
that don't depend on libcommon.
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
-rw-r--r-- | src/ceph_fuse.cc | 14 | ||||
-rw-r--r-- | src/common/secret.c | 11 | ||||
-rw-r--r-- | src/include/addr_parsing.c | 4 | ||||
-rw-r--r-- | src/librados.cc | 3 | ||||
-rw-r--r-- | src/librbd.cc | 20 | ||||
-rw-r--r-- | src/mds/MDLog.cc | 3 | ||||
-rw-r--r-- | src/mds/MDS.cc | 4 | ||||
-rw-r--r-- | src/messages/MPoolOpReply.h | 3 | ||||
-rwxr-xr-x | src/mount/mount.ceph.c | 4 | ||||
-rw-r--r-- | src/osd/ReplicatedPG.cc | 2 | ||||
-rw-r--r-- | src/rados.cc | 4 | ||||
-rw-r--r-- | src/rbd.cc | 42 | ||||
-rw-r--r-- | src/test/test_librbd.cc | 5 |
13 files changed, 69 insertions, 50 deletions
diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 552de42c5a7..140570c667d 100644 --- a/src/ceph_fuse.cc +++ b/src/ceph_fuse.cc @@ -18,6 +18,7 @@ using namespace std; #include "common/config.h" +#include "common/errno.h" #include "client/Client.h" #include "client/fuse_ll.h" @@ -102,7 +103,7 @@ int main(int argc, const char **argv, const char *envp[]) { if (g_conf->daemonize) { int r = socketpair(AF_UNIX, SOCK_STREAM, 0, fd); if (r < 0) { - cerr << "ceph-fuse[" << getpid() << "]: unable to create socketpair: " << strerror(errno) << std::endl; + cerr << "ceph-fuse[" << getpid() << "]: unable to create socketpair: " << cpp_strerror(errno) << std::endl; exit(1); } @@ -125,7 +126,7 @@ int main(int argc, const char **argv, const char *envp[]) { // use my argc, argv (make sure you pass a mount point!) int r = client->mount(g_conf->client_mountpoint.c_str()); if (r < 0) { - cerr << "ceph-fuse[" << getpid() << "]: ceph mount failed with " << strerror(-r) << std::endl; + cerr << "ceph-fuse[" << getpid() << "]: ceph mount failed with " << cpp_strerror(-r) << std::endl; goto out_shutdown; } @@ -164,10 +165,11 @@ int main(int argc, const char **argv, const char *envp[]) { ::close(0); ::close(1); ::close(2); - } else if (err) - cerr << "ceph-fuse[" << getpid() << "]: mount failed: " << strerror(-err) << std::endl; - else - cerr << "ceph-fuse[" << getpid() << "]: mount failed: " << strerror(-r) << std::endl; + } else if (err) { + cerr << "ceph-fuse[" << getpid() << "]: mount failed: " << cpp_strerror(-err) << std::endl; + } else { + cerr << "ceph-fuse[" << getpid() << "]: mount failed: " << cpp_strerror(-r) << std::endl; + } return r; } } diff --git a/src/common/secret.c b/src/common/secret.c index 3aa45c54e3a..b3caf966673 100644 --- a/src/common/secret.c +++ b/src/common/secret.c @@ -56,17 +56,20 @@ static int add_secret_to_kernel(const char *secret, const char *key_name) int ret; int secret_len = strlen(secret); char payload[((secret_len * 3) / 4) + 4]; + char error_buf[80]; ret = ceph_unarmor(payload, payload+sizeof(payload), secret, secret+secret_len); if (ret < 0) { - fprintf(stderr, "secret is not valid base64: %s.\n", strerror(-ret)); + fprintf(stderr, "secret is not valid base64: %s.\n", + strerror_r(-ret, error_buf, sizeof(error_buf))); return ret; } serial = add_key("ceph", key_name, payload, sizeof(payload), KEY_SPEC_USER_KEYRING); if (serial < 0) { ret = -errno; - fprintf(stderr, "error adding secret to kernel, key name %s: %s.\n", key_name, strerror(-ret)); + fprintf(stderr, "error adding secret to kernel, key name %s: %s.\n", + key_name, strerror_r(-ret, error_buf, sizeof(error_buf))); } return ret; @@ -77,6 +80,7 @@ int get_secret_option(const char *secret, const char *key_name, char *secret_opt int ret; int olen = strlen(secret) + strlen(key_name) + 7; char option[olen+1]; + char error_buf[80]; option[olen] = '\0'; @@ -87,7 +91,8 @@ int get_secret_option(const char *secret, const char *key_name, char *secret_opt snprintf(option, olen, "secret=%s", secret); ret = 0; } else { - fprintf(stderr, "adding ceph secret key to kernel failed: %s.\n", strerror(-ret)); + fprintf(stderr, "adding ceph secret key to kernel failed: %s.\n", + strerror_r(-ret, error_buf, sizeof(error_buf))); return ret; } } else { diff --git a/src/include/addr_parsing.c b/src/include/addr_parsing.c index b676fd85e2b..06e3be2320e 100644 --- a/src/include/addr_parsing.c +++ b/src/include/addr_parsing.c @@ -96,7 +96,9 @@ char *resolve_addrs(const char *orig_str) r = getaddrinfo(tok, port_str, &hint, &res); if (r < 0) { - printf("server name not found: %s (%s)\n", tok, strerror(errno)); + char error_buf[80]; + printf("server name not found: %s (%s)\n", tok, + strerror_r(errno, error_buf, sizeof(error_buf))); free(new_str); free(buf); return 0; diff --git a/src/librados.cc b/src/librados.cc index 1f31babb0e3..d03ff13e205 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -45,6 +45,7 @@ using namespace std; #include "include/rados/librados.hpp" #include "messages/MWatchNotify.h" +#include "common/errno.h" #define RADOS_LIST_MAX_ENTRIES 1024 #define DOUT_SUBSYS rados @@ -953,7 +954,7 @@ int librados::RadosClient::connect() err = monclient.authenticate(conf->client_mount_timeout); if (err) { - ldout(cct, 0) << conf->name << " authentication error " << strerror(-err) << dendl; + ldout(cct, 0) << conf->name << " authentication error " << cpp_strerror(-err) << dendl; shutdown(); goto out; } diff --git a/src/librbd.cc b/src/librbd.cc index e6c7fcd826f..8dc843d8a75 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -757,14 +757,14 @@ int create(IoCtx& io_ctx, const char *imgname, uint64_t size, int *order) ldout(cct, 2) << "adding rbd image to directory..." << dendl; r = tmap_set(io_ctx, imgname); if (r < 0) { - lderr(cct) << "error adding img to directory: " << strerror(-r)<< dendl; + lderr(cct) << "error adding img to directory: " << cpp_strerror(-r)<< dendl; return r; } ldout(cct, 2) << "creating rbd image..." << dendl; r = io_ctx.write(md_oid, bl, bl.length(), 0); if (r < 0) { - lderr(cct) << "error writing header: " << strerror(-r) << dendl; + lderr(cct) << "error writing header: " << cpp_strerror(-r) << dendl; return r; } @@ -787,7 +787,7 @@ int rename(IoCtx& io_ctx, const char *srcname, const char *dstname) bufferlist header; int r = read_header_bl(io_ctx, md_oid, header, &ver); if (r < 0) { - lderr(cct) << "error reading header: " << md_oid << ": " << strerror(-r) << dendl; + lderr(cct) << "error reading header: " << md_oid << ": " << cpp_strerror(-r) << dendl; return r; } r = io_ctx.stat(dst_md_oid, NULL, NULL); @@ -797,7 +797,7 @@ int rename(IoCtx& io_ctx, const char *srcname, const char *dstname) } r = write_header(io_ctx, dst_md_oid, header); if (r < 0) { - lderr(cct) << "error writing header: " << dst_md_oid << ": " << strerror(-r) << dendl; + lderr(cct) << "error writing header: " << dst_md_oid << ": " << cpp_strerror(-r) << dendl; return r; } r = tmap_set(io_ctx, dstname_str); @@ -843,7 +843,7 @@ int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx) struct rbd_obj_header_ondisk header; int r = read_header(io_ctx, md_oid, &header, NULL); if (r < 0) { - ldout(cct, 2) << "error reading header: " << strerror(-r) << dendl; + ldout(cct, 2) << "error reading header: " << cpp_strerror(-r) << dendl; } if (r >= 0) { trim_image(io_ctx, header, 0, prog_ctx); @@ -854,7 +854,7 @@ int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx) ldout(cct, 2) << "removing rbd image from directory..." << dendl; r = tmap_rm(io_ctx, imgname); if (r < 0) { - lderr(cct) << "error removing img from directory: " << strerror(-r) << dendl; + lderr(cct) << "error removing img from directory: " << cpp_strerror(-r) << dendl; return r; } @@ -895,7 +895,7 @@ int resize(ImageCtx *ictx, uint64_t size, ProgressContext& prog_ctx) if (r == -ERANGE) lderr(cct) << "operation might have conflicted with another client!" << dendl; if (r < 0) { - lderr(cct) << "error writing header: " << strerror(-r) << dendl; + lderr(cct) << "error writing header: " << cpp_strerror(-r) << dendl; return r; } else { notify_change(ictx->md_ctx, ictx->md_oid(), NULL, ictx); @@ -937,7 +937,7 @@ int add_snap(ImageCtx *ictx, const char *snap_name) int r = ictx->md_ctx.selfmanaged_snap_create(&snap_id); if (r < 0) { - lderr(ictx->cct) << "failed to create snap id: " << strerror(-r) << dendl; + lderr(ictx->cct) << "failed to create snap id: " << cpp_strerror(-r) << dendl; return r; } @@ -946,7 +946,7 @@ int add_snap(ImageCtx *ictx, const char *snap_name) r = ictx->md_ctx.exec(ictx->md_oid(), "rbd", "snap_add", bl, bl2); if (r < 0) { - lderr(ictx->cct) << "rbd.snap_add execution failed failed: " << strerror(-r) << dendl; + lderr(ictx->cct) << "rbd.snap_add execution failed failed: " << cpp_strerror(-r) << dendl; return r; } notify_change(ictx->md_ctx, ictx->md_oid(), NULL, ictx); @@ -963,7 +963,7 @@ int rm_snap(ImageCtx *ictx, const char *snap_name) int r = ictx->md_ctx.exec(ictx->md_oid(), "rbd", "snap_remove", bl, bl2); if (r < 0) { - lderr(ictx->cct) << "rbd.snap_remove execution failed: " << strerror(-r) << dendl; + lderr(ictx->cct) << "rbd.snap_remove execution failed: " << cpp_strerror(-r) << dendl; return r; } diff --git a/src/mds/MDLog.cc b/src/mds/MDLog.cc index 1862d4c511a..4d87ea321c2 100644 --- a/src/mds/MDLog.cc +++ b/src/mds/MDLog.cc @@ -25,6 +25,7 @@ #include "events/ESubtreeMap.h" #include "common/config.h" +#include "common/errno.h" #define DOUT_SUBSYS mds #undef DOUT_COND @@ -499,7 +500,7 @@ void MDLog::_replay_thread() while (!done) cond.Wait(mylock); if (err) { // well, crap - dout(0) << "got error while reading head: " << strerror(err) + dout(0) << "got error while reading head: " << cpp_strerror(err) << dendl; mds->suicide(); } diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 004e5333c80..d31e0acd223 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -69,6 +69,7 @@ #include "auth/KeyRing.h" #include "common/config.h" +#include "common/errno.h" #include "common/DoutStreambuf.h" #include "perfglue/cpu_profiler.h" @@ -1613,7 +1614,8 @@ void MDS::respawn() unblock_all_signals(NULL); execv(orig_argv[0], new_argv); - dout(0) << "respawn execv " << orig_argv[0] << " failed with " << strerror(errno) << dendl; + dout(0) << "respawn execv " << orig_argv[0] + << " failed with " << cpp_strerror(errno) << dendl; suicide(); } diff --git a/src/messages/MPoolOpReply.h b/src/messages/MPoolOpReply.h index 61958d83754..93ed7abd52d 100644 --- a/src/messages/MPoolOpReply.h +++ b/src/messages/MPoolOpReply.h @@ -15,6 +15,7 @@ #ifndef CEPH_MPOOLOPREPLY_H #define CEPH_MPOOLOPREPLY_H +#include "common/errno.h" class MPoolOpReply : public PaxosServiceMessage { public: @@ -46,7 +47,7 @@ public: const char *get_type_name() { return "poolopreply"; } void print(ostream& out) { - out << "poolopreply(reply:" << strerror(-replyCode) << ", " + out << "poolopreply(reply:" << cpp_strerror(-replyCode) << ", " << get_tid() << " v" << version << ")"; } diff --git a/src/mount/mount.ceph.c b/src/mount/mount.ceph.c index 37017f16c67..e7a247dfaef 100755 --- a/src/mount/mount.ceph.c +++ b/src/mount/mount.ceph.c @@ -298,7 +298,9 @@ static void modprobe(void) { int status; status = system("/sbin/modprobe ceph"); if (status < 0) { - fprintf(stderr, "mount.ceph: cannot run modprobe: %s\n", strerror(errno)); + char error_buf[80]; + fprintf(stderr, "mount.ceph: cannot run modprobe: %s\n", + strerror_r(errno, error_buf, sizeof(error_buf))); } else if (WIFEXITED(status)) { status = WEXITSTATUS(status); if (status != 0) { diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 20e8aa6d4b9..883bea368a7 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -1449,7 +1449,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops, break; } if (result < 0) { - dout(10) << "comparison returned " << result << " " << strerror(-result) << dendl; + dout(10) << "comparison returned " << result << " " << cpp_strerror(-result) << dendl; break; } diff --git a/src/rados.cc b/src/rados.cc index b462ec730af..2ac2d666ceb 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -36,6 +36,8 @@ using namespace librados; #include <errno.h> #include <dirent.h> +#include "common/errno.h" + int rados_tool_sync(const std::map < std::string, std::string > &opts, std::vector<const char*> &args); @@ -217,7 +219,7 @@ int gen_rand_alphanumeric(char *dest, int size) /* size should be the required s { int ret = get_random_bytes(dest, size); if (ret < 0) { - cerr << "cannot get random bytes: " << strerror(-ret) << std::endl; + cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl; return -1; } diff --git a/src/rbd.cc b/src/rbd.cc index 65564bbe32c..ca8a055f594 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1048,7 +1048,7 @@ int main(int argc, const char **argv) if (talk_to_cluster) { r = rados.ioctx_create(poolname, io_ctx); if (r < 0) { - cerr << "error opening pool " << poolname << ": " << strerror(-r) << std::endl; + cerr << "error opening pool " << poolname << ": " << cpp_strerror(-r) << std::endl; exit(1); } } @@ -1060,7 +1060,7 @@ int main(int argc, const char **argv) opt_cmd == OPT_COPY)) { r = rbd.open(io_ctx, image, imgname); if (r < 0) { - cerr << "error opening image " << imgname << ": " << strerror(-r) << std::endl; + cerr << "error opening image " << imgname << ": " << cpp_strerror(-r) << std::endl; exit(1); } } @@ -1068,7 +1068,7 @@ int main(int argc, const char **argv) if (snapname) { r = image.snap_set(snapname); if (r < 0 && !(r == -ENOENT && opt_cmd == OPT_SNAP_CREATE)) { - cerr << "error setting snapshot context: " << strerror(-r) << std::endl; + cerr << "error setting snapshot context: " << cpp_strerror(-r) << std::endl; exit(1); } } @@ -1076,7 +1076,7 @@ int main(int argc, const char **argv) if (opt_cmd == OPT_COPY || opt_cmd == OPT_IMPORT) { r = rados.ioctx_create(dest_poolname, dest_io_ctx); if (r < 0) { - cerr << "error opening pool " << dest_poolname << ": " << strerror(-r) << std::endl; + cerr << "error opening pool " << dest_poolname << ": " << cpp_strerror(-r) << std::endl; exit(1); } } @@ -1090,7 +1090,7 @@ int main(int argc, const char **argv) cerr << "pool " << poolname << " doesn't contain rbd images" << std::endl; break; default: - cerr << "error: " << strerror(-r) << std::endl; + cerr << "error: " << cpp_strerror(-r) << std::endl; } exit(1); } @@ -1109,7 +1109,7 @@ int main(int argc, const char **argv) } r = do_create(rbd, io_ctx, imgname, size, &order); if (r < 0) { - cerr << "create error: " << strerror(-r) << std::endl; + cerr << "create error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1117,7 +1117,7 @@ int main(int argc, const char **argv) case OPT_RENAME: r = do_rename(rbd, io_ctx, imgname, destname); if (r < 0) { - cerr << "rename error: " << strerror(-r) << std::endl; + cerr << "rename error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1125,7 +1125,7 @@ int main(int argc, const char **argv) case OPT_INFO: r = do_show_info(imgname, image); if (r < 0) { - cerr << "error: " << strerror(-r) << std::endl; + cerr << "error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1133,7 +1133,7 @@ int main(int argc, const char **argv) case OPT_RM: r = do_delete(rbd, io_ctx, imgname); if (r < 0) { - cerr << "delete error: " << strerror(-r) << std::endl; + cerr << "delete error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1141,7 +1141,7 @@ int main(int argc, const char **argv) case OPT_RESIZE: r = do_resize(image, size); if (r < 0) { - cerr << "resize error: " << strerror(-r) << std::endl; + cerr << "resize error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1153,7 +1153,7 @@ int main(int argc, const char **argv) } r = do_list_snaps(image); if (r < 0) { - cerr << "failed to list snapshots: " << strerror(-r) << std::endl; + cerr << "failed to list snapshots: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1165,7 +1165,7 @@ int main(int argc, const char **argv) } r = do_add_snap(image, snapname); if (r < 0) { - cerr << "failed to create snapshot: " << strerror(-r) << std::endl; + cerr << "failed to create snapshot: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1177,7 +1177,7 @@ int main(int argc, const char **argv) } r = do_rollback_snap(image, snapname); if (r < 0) { - cerr << "rollback failed: " << strerror(-r) << std::endl; + cerr << "rollback failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1189,7 +1189,7 @@ int main(int argc, const char **argv) } r = do_remove_snap(image, snapname); if (r < 0) { - cerr << "rollback failed: " << strerror(-r) << std::endl; + cerr << "rollback failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1201,7 +1201,7 @@ int main(int argc, const char **argv) } r = do_export(image, path); if (r < 0) { - cerr << "export error: " << strerror(-r) << std::endl; + cerr << "export error: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1213,7 +1213,7 @@ int main(int argc, const char **argv) } r = do_import(rbd, dest_io_ctx, destname, &order, path); if (r < 0) { - cerr << "import failed: " << strerror(-r) << std::endl; + cerr << "import failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1221,7 +1221,7 @@ int main(int argc, const char **argv) case OPT_COPY: r = do_copy(image, dest_io_ctx, destname); if (r < 0) { - cerr << "copy failed: " << strerror(-r) << std::endl; + cerr << "copy failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1229,7 +1229,7 @@ int main(int argc, const char **argv) case OPT_WATCH: r = do_watch(io_ctx, imgname); if (r < 0) { - cerr << "watch failed: " << strerror(-r) << std::endl; + cerr << "watch failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1237,7 +1237,7 @@ int main(int argc, const char **argv) case OPT_MAP: r = do_kernel_add(poolname, imgname, secretfile, user); if (r < 0) { - cerr << "add failed: " << strerror(-r) << std::endl; + cerr << "add failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1245,7 +1245,7 @@ int main(int argc, const char **argv) case OPT_UNMAP: r = do_kernel_rm(devpath); if (r < 0) { - cerr << "remove failed: " << strerror(-r) << std::endl; + cerr << "remove failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; @@ -1253,7 +1253,7 @@ int main(int argc, const char **argv) case OPT_SHOWMAPPED: r = do_kernel_showmapped(); if (r < 0) { - cerr << "showmapped failed: " << strerror(-r) << std::endl; + cerr << "showmapped failed: " << cpp_strerror(-r) << std::endl; exit(1); } break; diff --git a/src/test/test_librbd.cc b/src/test/test_librbd.cc index 42b300197b6..b43bf3837be 100644 --- a/src/test/test_librbd.cc +++ b/src/test/test_librbd.cc @@ -30,6 +30,7 @@ #include <algorithm> #include "rados-api/test.cc" +#include "common/errno.h" using namespace std; @@ -806,7 +807,7 @@ TEST(LibRBD, TestIOToSnapshot) r = rbd_write(image, 0, TEST_IO_TO_SNAP_SIZE, test_data); printf("write to snapshot returned %d\n", r); ASSERT_LT(r, 0); - printf("%s\n", strerror(-r)); + cout << cpp_strerror(-r) << std::endl; read_test_data(image, orig_data, 0, TEST_IO_TO_SNAP_SIZE); rbd_snap_set(image, "written"); @@ -826,7 +827,7 @@ TEST(LibRBD, TestIOToSnapshot) r = rbd_write(image_at_snap, 0, TEST_IO_TO_SNAP_SIZE, test_data); printf("write to snapshot returned %d\n", r); ASSERT_LT(r, 0); - printf("%s\n", strerror(-r)); + cout << cpp_strerror(-r) << std::endl; ASSERT_EQ(0, rbd_close(image_at_snap)); ASSERT_EQ(2, test_ls_snaps(image, 2, "orig", isize, "written", isize)); |