[Devel] [PATCH RHEL8 COMMIT] ploop: Move fget() code to separate function
Konstantin Khorenko
khorenko at virtuozzo.com
Thu May 6 00:32:30 MSK 2021
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.26
------>
commit ac6f703e97909357e1998312f1a3cb407128b16e
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date: Thu May 6 00:32:30 2021 +0300
ploop: Move fget() code to separate function
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
=====================
Patchset description:
ploop: Preparation to kill-loop from dm-ploop (series 3)
Currently, ploop requires underlining loop for top delta. This is overkill,
since we may submit bios directly to fs, without using it.
Initially there was a possibility, we may use device-mapper format snapshots
instead of ploop-based. But we don't do that, so we have to use loop for top
delta and directly submit bios to the rest of deltas. So, these two ways to do
the same actions are wrong.
This is preparations #3 for further series.
Let's this goes to testing earlier.
Kirill Tkhai (3):
ploop: Move fget() code to separate function
ploop: Move prealloc_pages()
ploop: Use prealloc_md_pages on ctr.
https://jira.sw.ru/browse/PSBM-123654
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
drivers/md/dm-ploop-bat.c | 12 +-----------
drivers/md/dm-ploop-target.c | 30 ++++++++++++++++++++++++++----
drivers/md/dm-ploop.h | 2 +-
3 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index c17f874fc25d..ba912001dca9 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -476,21 +476,13 @@ static int ploop_check_delta_length(struct ploop *ploop, struct file *file,
* @fd refers to a new delta, which is placed right before top_delta.
* So, userspace has to populate deltas stack from oldest to newest.
*/
-int ploop_add_delta(struct ploop *ploop, u32 level, int fd, bool is_raw)
+int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_raw)
{
struct ploop_delta *deltas = ploop->deltas;
struct ploop_pvd_header *hdr = NULL;
- struct file *file;
u32 size_in_clus;
int ret;
- file = fget(fd);
- if (!file)
- return -ENOENT;
- ret = -EBADF;
- if (!(file->f_mode & FMODE_READ))
- goto out;
-
ret = ploop_check_delta_length(ploop, file, &size_in_clus);
if (ret)
goto out;
@@ -515,7 +507,5 @@ int ploop_add_delta(struct ploop *ploop, u32 level, int fd, bool is_raw)
ret = 0;
out:
vfree(hdr);
- if (ret)
- fput(file);
return ret;
}
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 39c39a77b05f..155327242fc5 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -116,13 +116,28 @@ static int ploop_check_origin_dev(struct dm_target *ti, struct ploop *ploop)
return 0;
}
+static struct file * get_delta_file(int fd)
+{
+ struct file *file;
+
+ file = fget(fd);
+ if (!file)
+ return ERR_PTR(-ENOENT);
+ if (!(file->f_mode & FMODE_READ)) {
+ fput(file);
+ return ERR_PTR(-EBADF);
+ }
+
+ return file;
+}
+
static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
{
struct ploop_delta *deltas;
int i, delta_fd, ret = 0;
+ struct file *file;
const char *arg;
bool is_raw;
- u32 level;
if (!argc)
goto out;
@@ -150,10 +165,17 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
if (kstrtos32(arg, 10, &delta_fd) < 0)
goto out;
- level = i;
- ret = ploop_add_delta(ploop, level, delta_fd, is_raw);
- if (ret < 0)
+ file = get_delta_file(delta_fd);
+ if (IS_ERR(file)) {
+ ret = PTR_ERR(file);
goto out;
+ }
+
+ ret = ploop_add_delta(ploop, i, file, is_raw);
+ if (ret < 0) {
+ fput(file);
+ goto out;
+ }
}
ret = 0;
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index e21a0ab83378..d0c613b743b8 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -488,7 +488,7 @@ extern void free_md_pages_tree(struct rb_root *root);
extern bool try_update_bat_entry(struct ploop *ploop, unsigned int cluster,
u8 level, unsigned int dst_cluster);
-extern int ploop_add_delta(struct ploop *ploop, u32 level, int fd, bool is_raw);
+extern int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_raw);
extern void defer_bios(struct ploop *ploop, struct bio *bio, struct bio_list *bio_list);
extern void do_ploop_work(struct work_struct *ws);
extern void process_deferred_cmd(struct ploop *ploop,
More information about the Devel
mailing list