Skip to content

Commit

Permalink
removed do_io_in_core, now works via IOP.status
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Nov 11, 2022
1 parent 18ca01f commit 6910cdc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
14 changes: 6 additions & 8 deletions core/src/filed/fd_plugins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1831,18 +1831,16 @@ static int MyPluginBopen(BareosFilePacket* bfd,
errno = io.io_errno;
bfd->lerror = io.lerror;
}
// The plugin has two options for the read/write:
// 1.: - Set io.do_io_in_core to true, and
// The plugin has two options for the read/write during the IO_OPEN call:
// 1.: - Set io.status to IoStatus::do_io_in_core, and
// - Set the io.filedes to the filedescriptor of the file that was
// opened in the plugin. In this case the core code will read from
// write to that filedescriptor during backup and restore.
// 2.: - Set io.do_io_in_core to false , and
// - Set/leave the io.filedes on/to -1. In this case the plugin code
// itself will be called for every read/write during backup and
// restore.

bfd->do_io_in_core = io.do_io_in_core;
// 2.: - Set io.status to IoStatus::success, and
bfd->filedes = io.filedes;

if (io.status == IoStatus::do_io_in_core) { bfd->do_io_in_core = true; }

if (bfd->do_io_in_core) {
if (io.filedes != -1) {
Dmsg1(
Expand Down
38 changes: 22 additions & 16 deletions core/src/filed/fd_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ struct BareosFilePacket;
struct FindFilesPacket;
#endif /* FILE_DAEMON */

enum IoStatus : int
{
error = -1,
success = 0,
do_io_in_core = 1,
};

template <typename T> class alist;

namespace filedaemon {
Expand Down Expand Up @@ -138,22 +145,21 @@ enum
};

struct io_pkt {
int32_t pkt_size; /* Size of this packet */
int32_t func; /* Function code */
int32_t count; /* Read/write count */
int32_t flags; /* Open flags */
mode_t mode; /* Permissions for created files */
char* buf; /* Read/write buffer */
const char* fname; /* Open filename */
int32_t status; /* Return status */
int32_t io_errno; /* Errno code */
int32_t lerror; /* Win32 error code */
int32_t whence; /* Lseek argument */
boffset_t offset; /* Lseek argument */
bool win32; /* Win32 GetLastError returned */
int filedes; /* file descriptor to read/write in core */
bool do_io_in_core; /* do io in core */
int32_t pkt_end; /* End packet sentinel */
int32_t pkt_size; /* Size of this packet */
int32_t func; /* Function code */
int32_t count; /* Read/write count */
int32_t flags; /* Open flags */
mode_t mode; /* Permissions for created files */
char* buf; /* Read/write buffer */
const char* fname; /* Open filename */
int32_t status; /* Return status */
int32_t io_errno; /* Errno code */
int32_t lerror; /* Win32 error code */
int32_t whence; /* Lseek argument */
boffset_t offset; /* Lseek argument */
bool win32; /* Win32 GetLastError returned */
int filedes; /* file descriptor to read/write in core */
int32_t pkt_end; /* End packet sentinel */
};

struct acl_pkt {
Expand Down
2 changes: 0 additions & 2 deletions core/src/plugins/filed/python/module/bareosfd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ static inline PyIoPacket* NativeToPyIoPacket(struct io_pkt* io)
pIoPkt->whence = io->whence;
pIoPkt->offset = io->offset;
pIoPkt->filedes = io->filedes;
pIoPkt->do_io_in_core = io->do_io_in_core;

if (io->func == IO_WRITE && io->count > 0) {
/* Only initialize the buffer with read data when we are writing and
Expand Down Expand Up @@ -540,7 +539,6 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io)
io->win32 = pIoPkt->win32;
io->status = pIoPkt->status;
io->filedes = pIoPkt->filedes;
io->do_io_in_core = pIoPkt->do_io_in_core;

if (io->func == IO_READ && io->status > 0) {
// Only copy back the data when doing a read and there is data.
Expand Down
10 changes: 10 additions & 0 deletions core/src/plugins/filed/python/module/bareosfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,16 @@ MOD_INIT(bareosfd)
if (!pDictbIOPS) { return MOD_ERROR_VAL; }
if (PyModule_AddObject(m, bIOPS, pDictbIOPS)) { return MOD_ERROR_VAL; }

const char* bIOPstatus = "bIOPstatus";
PyObject* pDictbIOPstatus = NULL;
pDictbIOPstatus = PyDict_New();
ConstSet_StrLong(pDictbIOPstatus, io_status_error, -1);
ConstSet_StrLong(pDictbIOPstatus, io_status_plugin, 0);
ConstSet_StrLong(pDictbIOPstatus, io_status_core, 1);
if (!pDictbIOPstatus) { return MOD_ERROR_VAL; }
if (PyModule_AddObject(m, bIOPstatus, pDictbIOPstatus)) { return MOD_ERROR_VAL; }



const char* bLevels = "bLevels";
PyObject* pDictbLevels = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ def plugin_io_open(self, IOP):
self.file = open(self.FNAME, "rb")

# do io in core
IOP.do_io_in_core = True
IOP.filedes = self.file.fileno()
#IOP.filedes = self.file.fileno()
#IOP.status = bareosfd.io_status_core
##IOP.status = 1

# do io in plugin
IOP.status = bareosfd.io_status_plugin
##IOP.status = 0

except:
IOP.status = -1
Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/filed/python/test/bareosfd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import time
import types

# print dir(bareosfd)
#print(dir(bareosfd))
print ("bareosfd.io_status_error: ", bareosfd.io_status_error)
print ("bareosfd.io_status_core: ", bareosfd.io_status_core)
print ("bareosfd.io_status_plugin: ", bareosfd.io_status_plugin)
# print "bareosfd.bJobMessageType:", str( bareosfd.bJobMessageType)
# print "bareosfd.bVariable:", str( bareosfd.bVariable)
# print "bareosfd.bEventType:", str( bareosfd.bEventType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ setup_data
# using Python3
find ${tmp}/data/weird-files -type l -exec rm {} \;
find tmp/data/weird-files -links +1 -type f -exec rm {} \;

rm tmp/data/weird-files/*utf*
print_debug "$(locale)"

start_test
Expand Down

0 comments on commit 6910cdc

Please sign in to comment.