Skip to content

Commit

Permalink
Merge pull request ceph#957 from ceph/wip-rbd-coverity
Browse files Browse the repository at this point in the history
rbd: make coverity happy

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Dec 17, 2013
2 parents 6f43120 + 0edbda2 commit 526e252
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1720,27 +1720,29 @@ static int do_kernel_add(const char *poolname, const char *imgname,
}
}

// 'add' interface is deprecated, see if 'add_single_major' is
// available and use it if it is
// 'add' interface is deprecated, use 'add_single_major' if it's
// available
//
// ('add' and 'add_single_major' interfaces are identical, except
// that if rbd kernel module is new enough and is configured to use
// single-major scheme, 'add' is disabled in order to prevent old
// userspace from doing weird things at unmap time)
const char *fname = "/sys/bus/rbd/add_single_major";
if (stat(fname, &sb)) {
fname = "/sys/bus/rbd/add";
}

int fd = open(fname, O_WRONLY);
int fd = open("/sys/bus/rbd/add_single_major", O_WRONLY);
if (fd < 0) {
r = -errno;
if (r == -ENOENT) {
cerr << "rbd: /sys/bus/rbd/add does not exist!" << std::endl
<< "Did you run 'modprobe rbd' or is your rbd module too old?"
<< std::endl;
if (errno == ENOENT) {
fd = open("/sys/bus/rbd/add", O_WRONLY);
if (fd < 0) {
r = -errno;
if (r == -ENOENT) {
cerr << "rbd: /sys/bus/rbd/add does not exist!" << std::endl
<< "Did you run 'modprobe rbd' or is your rbd module too old?"
<< std::endl;
}
return r;
}
} else {
return -errno;
}
return r;
}

string add = oss.str();
Expand Down Expand Up @@ -2016,14 +2018,15 @@ static int do_kernel_rm(const char *dev)

// see comment in do_kernel_add(), same goes for 'remove' vs
// 'remove_single_major'
const char *fname = "/sys/bus/rbd/remove_single_major";
if (stat(fname, &sbuf)) {
fname = "/sys/bus/rbd/remove";
}

int fd = open(fname, O_WRONLY);
int fd = open("/sys/bus/rbd/remove_single_major", O_WRONLY);
if (fd < 0) {
return -errno;
if (errno == ENOENT) {
fd = open("/sys/bus/rbd/remove", O_WRONLY);
if (fd < 0)
return -errno;
} else {
return -errno;
}
}

r = safe_write(fd, seq_num.c_str(), seq_num.size());
Expand Down

0 comments on commit 526e252

Please sign in to comment.