]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
store: fix issues reported by coverity
authorYan, Zheng <zheng.z.yan@intel.com>
Wed, 21 Aug 2013 05:26:50 +0000 (13:26 +0800)
committerSage Weil <sage@inktank.com>
Thu, 22 Aug 2013 04:55:10 +0000 (21:55 -0700)
Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/os/BtrfsFileStoreBackend.cc
src/tools/ceph-monstore-tool.cc

index 580a4b5bebf01ff4d318bb6dea2082cc514611c7..9fa96babab780dc39fdf3575520dfc04edaf0d84 100644 (file)
@@ -51,7 +51,8 @@
 #define ALIGN_UP(x, by) (ALIGNED((x), (by)) ? (x) : (ALIGN_DOWN((x), (by)) + (by)))
 
 BtrfsFileStoreBackend::BtrfsFileStoreBackend(FileStore *fs):
-    GenericFileStoreBackend(fs), has_clone_range(false), has_snap_create(false),
+    GenericFileStoreBackend(fs), has_clone_range(false),
+    has_snap_create(false), has_snap_destroy(false),
     has_snap_create_v2(false), has_wait_sync(false), stable_commits(false),
     m_filestore_btrfs_clone_range(g_conf->filestore_btrfs_clone_range),
     m_filestore_btrfs_snap (g_conf->filestore_btrfs_snap) { }
@@ -298,8 +299,10 @@ int BtrfsFileStoreBackend::create_current()
 
 int BtrfsFileStoreBackend::list_checkpoints(list<string>& ls)
 {
+  int ret, err = 0;
+
   struct stat basest;
-  int ret = ::fstat(get_basedir_fd(), &basest);
+  ret = ::fstat(get_basedir_fd(), &basest);
   if (ret < 0) {
     ret = -errno;
     dout(0) << "list_checkpoints: cannot fstat basedir " << cpp_strerror(ret) << dendl;
@@ -327,10 +330,10 @@ int BtrfsFileStoreBackend::list_checkpoints(list<string>& ls)
     struct stat st;
     ret = ::stat(path, &st);
     if (ret < 0) {
-      ret = -errno;
+      err = -errno;
       dout(0) << "list_checkpoints: stat '" << path << "' failed: "
-             << cpp_strerror(ret) << dendl;
-      return ret;
+             << cpp_strerror(err) << dendl;
+      break;
     }
 
     if (!S_ISDIR(st.st_mode))
@@ -339,10 +342,10 @@ int BtrfsFileStoreBackend::list_checkpoints(list<string>& ls)
     struct statfs fs;
     ret = ::statfs(path, &fs);
     if (ret < 0) {
-      ret = -errno;
+      err = -errno;
       dout(0) << "list_checkpoints: statfs '" << path << "' failed: "
-             << cpp_strerror(ret) << dendl;
-      return ret;
+             << cpp_strerror(err) << dendl;
+      break;
     }
 
     if (fs.f_type == BTRFS_SUPER_MAGIC && basest.st_dev != st.st_dev)
@@ -352,9 +355,13 @@ int BtrfsFileStoreBackend::list_checkpoints(list<string>& ls)
   if (::closedir(dir) < 0) {
       ret = -errno;
       dout(0) << "list_checkpoints: closedir failed: " << cpp_strerror(ret) << dendl;
-      return ret;
+      if (!err)
+       err = ret;
   }
 
+  if (err)
+    return err;
+
   ls.swap(snaps);
   return 0;
 }
@@ -367,7 +374,7 @@ int BtrfsFileStoreBackend::create_checkpoint(const string& name, uint64_t *trans
     memset(&async_args, 0, sizeof(async_args));
     async_args.fd = get_current_fd();
     async_args.flags = BTRFS_SUBVOL_CREATE_ASYNC;
-    strcpy(async_args.name, name.c_str());
+    strncpy(async_args.name, name.c_str(), sizeof(async_args.name));
 
     int r = ::ioctl(get_basedir_fd(), BTRFS_IOC_SNAP_CREATE_V2, &async_args);
     if (r < 0) {
@@ -455,7 +462,7 @@ int BtrfsFileStoreBackend::destroy_checkpoint(const string& name)
   btrfs_ioctl_vol_args vol_args;
   memset(&vol_args, 0, sizeof(vol_args));
   vol_args.fd = 0;
-  strcpy(vol_args.name, name.c_str());
+  strncpy(vol_args.name, name.c_str(), sizeof(vol_args.name));
 
   int ret = ::ioctl(get_basedir_fd(), BTRFS_IOC_SNAP_DESTROY, &vol_args);
   if (ret) {
index 4ab8fa86465cc144968560753f034b89ee42ccc2..7d9ea628e9fd474c9e81513b7660e0873eaac054 100644 (file)
@@ -179,7 +179,7 @@ int main(int argc, char **argv) {
 
   int fd;
   if (vm.count("out")) {
-    if ((fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
+    if ((fd = open(out_path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
       int _err = errno;
       if (_err != EISDIR) {
         std::cerr << "Couldn't open " << out_path << ": " << cpp_strerror(_err) << std::endl;