diff options
author | Philipp Storz <philipp.storz@bareos.com> | 2022-10-28 15:18:32 +0300 |
---|---|---|
committer | Philipp Storz <philipp.storz@bareos.com> | 2022-11-11 22:26:08 +0300 |
commit | 5399c8219aeb36215e07349fbd8f6b414997753e (patch) | |
tree | 5c64676cd8360a31be65e314a06e0f2f467e8715 | |
parent | 121dc5d2b85850fd813ffa212ba8c72cf70ce3e9 (diff) |
BareosFdPluginLocalFileset.py: use direct I/O
Implement `plugin_io_open()` so that we can configure direct I/O and pass
the filedescriptor.
-rw-r--r-- | core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py index bb8a37f85..db3d1b608 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# Copyright (C) 2014-2022 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -132,3 +132,69 @@ class BareosFdPluginLocalFileset(BareosFdPluginLocalFilesBaseclass): # noqa return bareosfd.bRC_Error else: return bareosfd.bRC_OK + + + + def plugin_io_open(self, IOP): + self.FNAME = IOP.fname + bareosfd.DebugMessage(250, "io_open: self.FNAME is set to %s\n" % (self.FNAME)) + if os.path.isdir(self.FNAME): + bareosfd.DebugMessage(100, "%s is a directory\n" % (self.FNAME)) + self.fileType = "FT_DIR" + bareosfd.DebugMessage( + 100, + "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), + ) + return bareosfd.bRC_OK + elif os.path.islink(self.FNAME): + self.fileType = "FT_LNK" + bareosfd.DebugMessage( + 100, + "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), + ) + return bareosfd.bRC_OK + elif os.path.exists(self.FNAME) and stat.S_ISFIFO(os.stat(self.FNAME).st_mode): + self.fileType = "FT_FIFO" + bareosfd.DebugMessage( + 100, + "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), + ) + return bareosfd.bRC_OK + else: + self.fileType = "FT_REG" + bareosfd.DebugMessage( + 150, + "file %s has type %s - trying to open it\n" + % (self.FNAME, self.fileType), + ) + try: + if IOP.flags & (os.O_CREAT | os.O_WRONLY): + bareosfd.DebugMessage( + 100, + "Open file %s for writing with %s\n" % (self.FNAME, IOP), + ) + dirname = os.path.dirname(self.FNAME) + if not os.path.exists(dirname): + bareosfd.DebugMessage( + 100, + "Directory %s does not exist, creating it now\n" % (dirname), + ) + os.makedirs(dirname) + self.file = open(self.FNAME, "wb") + else: + bareosfd.DebugMessage( + 100, + "Open file %s for reading with %s\n" % (self.FNAME, IOP), + ) + self.file = open(self.FNAME, "rb") + + # do io in core + IOP.do_io_in_core = True + IOP.filedes = self.file.fileno() + + except: + IOP.status = -1 + return bareosfd.bRC_Error + + return bareosfd.bRC_OK + |