Skip to content

Commit

Permalink
device: do not use a getter for file descriptor
Browse files Browse the repository at this point in the history
- rename file descriptor variable
  • Loading branch information
franku committed Mar 25, 2021
1 parent 152a1b2 commit d443749
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 144 deletions.
16 changes: 8 additions & 8 deletions core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static bRC do_set_scsi_encryption_key(void* value)
* Check if encryption key is needed for reading this volume.
*/
P(crypto_operation_mutex);
if (!NeedScsiCryptoKey(dev->fd(), dev->archive_device_string, true)) {
if (!NeedScsiCryptoKey(dev->fd, dev->archive_device_string, true)) {
V(crypto_operation_mutex);
Dmsg0(debuglevel, "scsicrypto-sd: No encryption key needed!\n");
return bRC_OK;
Expand Down Expand Up @@ -396,7 +396,7 @@ static bRC do_set_scsi_encryption_key(void* value)
Dmsg1(debuglevel, "scsicrypto-sd: Loading new crypto key %s\n", VolEncrKey);

P(crypto_operation_mutex);
if (SetScsiEncryptionKey(dev->fd(), dev->archive_device_string, VolEncrKey)) {
if (SetScsiEncryptionKey(dev->fd, dev->archive_device_string, VolEncrKey)) {
dev->SetCryptoEnabled();
V(crypto_operation_mutex);
return bRC_OK;
Expand Down Expand Up @@ -444,13 +444,13 @@ static bRC do_clear_scsi_encryption_key(void* value)
*/
if (device_resource->query_crypto_status) {
need_to_clear
= IsScsiEncryptionEnabled(dev->fd(), dev->archive_device_string);
= IsScsiEncryptionEnabled(dev->fd, dev->archive_device_string);
} else {
need_to_clear = dev->IsCryptoEnabled();
}
if (need_to_clear) {
Dmsg0(debuglevel, "scsicrypto-sd: Clearing crypto key\n");
if (ClearScsiEncryptionKey(dev->fd(), dev->archive_device_string)) {
if (ClearScsiEncryptionKey(dev->fd, dev->archive_device_string)) {
dev->ClearCryptoEnabled();
V(crypto_operation_mutex);
return bRC_OK;
Expand Down Expand Up @@ -503,7 +503,7 @@ static bRC handle_read_error(void* value)
*/
if (device_resource->query_crypto_status) {
P(crypto_operation_mutex);
if (NeedScsiCryptoKey(dev->fd(), dev->archive_device_string, false)) {
if (NeedScsiCryptoKey(dev->fd, dev->archive_device_string, false)) {
decryption_needed = true;
} else {
decryption_needed = false;
Expand All @@ -525,7 +525,7 @@ static bRC handle_read_error(void* value)
dev->errmsg,
_("Read error on fd=%d at file:blk %u:%u on device %s. ERR=%s.\n"
"Probably due to reading encrypted data from volume\n"),
dev->fd(), dev->file, dev->block_num, dev->print_name(),
dev->fd, dev->file, dev->block_num, dev->print_name(),
be.bstrerror());
}
break;
Expand All @@ -552,7 +552,7 @@ static bRC send_device_encryption_status(void* value)
if (dst->device_resource->drive_crypto_enabled) {
P(crypto_operation_mutex);
dst->status_length = GetScsiDriveEncryptionStatus(
dst->device_resource->dev->fd(),
dst->device_resource->dev->fd,
dst->device_resource->dev->archive_device_string, dst->status, 4);
V(crypto_operation_mutex);
}
Expand All @@ -575,7 +575,7 @@ static bRC send_volume_encryption_status(void* value)
if (dst->device_resource->drive_crypto_enabled) {
P(crypto_operation_mutex);
dst->status_length = GetScsiVolumeEncryptionStatus(
dst->device_resource->dev->fd(),
dst->device_resource->dev->fd,
dst->device_resource->dev->archive_device_string, dst->status, 4);
V(crypto_operation_mutex);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static bRC handle_tapealert_readout(void* value)
Dmsg1(debuglevel, "scsitapealert-sd: checking for tapealerts on device %s\n",
dev->archive_device_string);
P(tapealert_operation_mutex);
GetTapealertFlags(dev->fd(), dev->archive_device_string, &flags);
GetTapealertFlags(dev->fd, dev->archive_device_string, &flags);
V(tapealert_operation_mutex);

Dmsg1(debuglevel,
Expand Down
58 changes: 29 additions & 29 deletions core/src/stored/backends/cephfs_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ int cephfs_device::d_open(const char* pathname, int flags, int mode)
/*
* See if we don't have a file open already.
*/
if (fd_ >= 0) {
ceph_close(cmount_, fd_);
fd_ = -1;
if (fd >= 0) {
ceph_close(cmount_, fd);
fd = -1;
}

/*
Expand Down Expand Up @@ -207,8 +207,8 @@ int cephfs_device::d_open(const char* pathname, int flags, int mode)
Mmsg(virtual_filename_, "%s", getVolCatName());
}

fd_ = ceph_open(cmount_, virtual_filename_, flags, mode);
if (fd_ < 0) { goto bail_out; }
fd = ceph_open(cmount_, virtual_filename_, flags, mode);
if (fd < 0) { goto bail_out; }

return 0;

Expand All @@ -220,7 +220,7 @@ int cephfs_device::d_open(const char* pathname, int flags, int mode)
ceph_shutdown(cmount_);
cmount_ = NULL;
}
fd_ = -1;
fd = -1;

return -1;
}
Expand All @@ -230,8 +230,8 @@ int cephfs_device::d_open(const char* pathname, int flags, int mode)
*/
ssize_t cephfs_device::d_read(int fd, void* buffer, size_t count)
{
if (fd_ >= 0) {
return ceph_read(cmount_, fd_, (char*)buffer, count, -1);
if (fd >= 0) {
return ceph_read(cmount_, fd, (char*)buffer, count, -1);
} else {
errno = EBADF;
return -1;
Expand All @@ -243,8 +243,8 @@ ssize_t cephfs_device::d_read(int fd, void* buffer, size_t count)
*/
ssize_t cephfs_device::d_write(int fd, const void* buffer, size_t count)
{
if (fd_ >= 0) {
return ceph_write(cmount_, fd_, (char*)buffer, count, -1);
if (fd >= 0) {
return ceph_write(cmount_, fd, (char*)buffer, count, -1);
} else {
errno = EBADF;
return -1;
Expand All @@ -253,11 +253,11 @@ ssize_t cephfs_device::d_write(int fd, const void* buffer, size_t count)

int cephfs_device::d_close(int fd)
{
if (fd_ >= 0) {
if (fd >= 0) {
int status;

status = ceph_close(cmount_, fd_);
fd_ = -1;
status = ceph_close(cmount_, fd);
fd = -1;
return (status < 0) ? -1 : 0;
} else {
errno = EBADF;
Expand All @@ -271,10 +271,10 @@ boffset_t cephfs_device::d_lseek(DeviceControlRecord* dcr,
boffset_t offset,
int whence)
{
if (fd_ >= 0) {
if (fd >= 0) {
boffset_t status;

status = ceph_lseek(cmount_, fd_, offset, whence);
status = ceph_lseek(cmount_, fd, offset, whence);
if (status >= 0) {
return status;
} else {
Expand All @@ -297,8 +297,8 @@ bool cephfs_device::d_truncate(DeviceControlRecord* dcr)
struct stat st;
# endif

if (fd_ >= 0) {
status = ceph_ftruncate(cmount_, fd_, 0);
if (fd >= 0) {
status = ceph_ftruncate(cmount_, fd, 0);
if (status < 0) {
BErrNo be;

Expand All @@ -318,9 +318,9 @@ bool cephfs_device::d_truncate(DeviceControlRecord* dcr)
* 4. change ownership to original
*/
# if HAVE_CEPH_STATX
status = ceph_fstatx(cmount_, fd_, &stx, CEPH_STATX_MODE, 0);
status = ceph_fstatx(cmount_, fd, &stx, CEPH_STATX_MODE, 0);
# else
status = ceph_fstat(cmount_, fd_, &st);
status = ceph_fstat(cmount_, fd, &st);
# endif
if (status < 0) {
BErrNo be;
Expand All @@ -341,27 +341,27 @@ bool cephfs_device::d_truncate(DeviceControlRecord* dcr)
# else
if (st.st_size != 0) { /* ceph_ftruncate() didn't work */
# endif
ceph_close(cmount_, fd_);
ceph_close(cmount_, fd);
ceph_unlink(cmount_, virtual_filename_);

/*
* Recreate the file -- of course, empty
*/
oflags = O_CREAT | O_RDWR | O_BINARY;
# if HAVE_CEPH_STATX
fd_ = ceph_open(cmount_, virtual_filename_, oflags, stx.stx_mode);
fd = ceph_open(cmount_, virtual_filename_, oflags, stx.stx_mode);
# else
fd_ = ceph_open(cmount_, virtual_filename_, oflags, st.st_mode);
fd = ceph_open(cmount_, virtual_filename_, oflags, st.st_mode);
# endif
if (fd_ < 0) {
if (fd < 0) {
BErrNo be;

dev_errno = -fd_;
dev_errno = -fd;
;
Mmsg2(errmsg, _("Could not reopen: %s, ERR=%s\n"), virtual_filename_,
be.bstrerror(-fd_));
be.bstrerror(-fd));
Emsg0(M_FATAL, 0, errmsg);
fd_ = -1;
fd = -1;

return false;
}
Expand All @@ -382,9 +382,9 @@ bool cephfs_device::d_truncate(DeviceControlRecord* dcr)

cephfs_device::~cephfs_device()
{
if (cmount_ && fd_ >= 0) {
ceph_close(cmount_, fd_);
fd_ = -1;
if (cmount_ && fd >= 0) {
ceph_close(cmount_, fd);
fd = -1;
}

if (!cmount_) {
Expand Down

0 comments on commit d443749

Please sign in to comment.