Skip to content

Commit

Permalink
use diff_storage_filename instead diff_storage_fd
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeiShtepa committed Jan 9, 2024
1 parent 51ae1fa commit b8354f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
6 changes: 3 additions & 3 deletions include/linux/blksnap.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ struct blksnap_version {
*
* @diff_storage_limit_sect:
* The maximum allowed difference storage size in sectors.
* @diff_storage_fd:
* The difference storage file descriptor.
* @diff_storage_filename:
* The difference storage file name.
* @id:
* Generated new snapshot ID.
*/
struct blksnap_snapshot_create {
__u64 diff_storage_limit_sect;
__u32 diff_storage_fd;
__u64 diff_storage_filename;
struct blksnap_uuid id;
};

Expand Down
11 changes: 1 addition & 10 deletions lib/blksnap/Snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,9 @@ void CSnapshot::Version(struct blksnap_version& version)

std::shared_ptr<CSnapshot> CSnapshot::Create(const std::string& filePath, const unsigned long long limit)
{
int flags = O_RDWR | O_EXCL;

if (fs::is_directory(filePath))
flags |= O_TMPFILE;
else if (!fs::is_regular_file(filePath) && !isBlockFile(filePath))
throw std::invalid_argument("The filePath should have been either the name of a regular file, the name of a block device, or the directory for creating a temporary file.");

OpenFileHolder fd(filePath, flags, 0600);

struct blksnap_snapshot_create param = {0};
param.diff_storage_limit_sect = limit / 512;
param.diff_storage_fd = fd.Get();
param.diff_storage_filename = (__u64)filePath.c_str();

auto ctl = OpenBlksnapCtl();
if (::ioctl(ctl->Get(), IOCTL_BLKSNAP_SNAPSHOT_CREATE, &param))
Expand Down
14 changes: 1 addition & 13 deletions tools/blksnap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,8 @@ class SnapshotCreateArgsProc : public IArgsProc
if (!vm.count("file"))
throw std::invalid_argument("Argument 'file' is missed.");

int flags = O_RDWR | O_EXCL;
std::string filename = vm["file"].as<std::string>();

if (fs::is_directory(filename)) {
/* A temporary file (flag O_TMPFILE) is being created.
* Not available for all file systems.
* See: man open.
*/
flags |= O_TMPFILE;
} else if (!fs::is_regular_file(filename) && !isBlockFile(filename))
throw std::invalid_argument("The value '"+filename+"' for the argument '--file' should have been either the name of a regular file, the name of a block device, or the directory for creating a temporary file.");

OpenFileHolder fd(filename, flags, 0600);

unsigned long long limit = 0;
unsigned long long multiple = 1;
if (!vm.count("limit"))
Expand All @@ -713,7 +701,7 @@ class SnapshotCreateArgsProc : public IArgsProc
}

param.diff_storage_limit_sect = limit / 512;
param.diff_storage_fd = fd.Get();
param.diff_storage_filename = (__u64)filename.c_str();
if (::ioctl(blksnapFd.get(), IOCTL_BLKSNAP_SNAPSHOT_CREATE, &param))
throw std::system_error(errno, std::generic_category(), "Failed to create snapshot object.");

Expand Down

0 comments on commit b8354f9

Please sign in to comment.