|
|
2f13d7 |
From 5f762af17c6e72e86e4710975dcdfd71fc5d1b07 Mon Sep 17 00:00:00 2001
|
|
|
2f13d7 |
From: chantra <chantr4@gmail.com>
|
|
|
2f13d7 |
Date: Tue, 8 Feb 2022 18:24:12 -0800
|
|
|
2f13d7 |
Subject: [PATCH 19/30] [reflink] use `rpmpluginsCallFsmFileArchiveReader` to
|
|
|
2f13d7 |
provide custom rpmfi
|
|
|
2f13d7 |
|
|
|
2f13d7 |
As the plugin can now be responsible to provide an Archive Reader to
|
|
|
2f13d7 |
`rpmPackageFilesInstall`, we also don't need to mutate the
|
|
|
2f13d7 |
`RPMTAG_PAYLOADFORMAT` header in memory, removing some special-casing.
|
|
|
2f13d7 |
---
|
|
|
2f13d7 |
lib/depends.c | 2 --
|
|
|
bd9c00 |
lib/fsm.c | 48 ++++++++++++++++++++++++++---------------------
|
|
|
2f13d7 |
plugins/reflink.c | 18 +++++++++++++-----
|
|
|
bd9c00 |
3 files changed, 40 insertions(+), 28 deletions(-)
|
|
|
2f13d7 |
|
|
|
2f13d7 |
diff --git a/lib/depends.c b/lib/depends.c
|
|
|
2f13d7 |
index 8998afcd3..30234df3d 100644
|
|
|
2f13d7 |
--- a/lib/depends.c
|
|
|
2f13d7 |
+++ b/lib/depends.c
|
|
|
bd9c00 |
@@ -80,8 +80,6 @@ static rpmRC headerCheckPayloadFormat(Header h) {
|
|
|
2f13d7 |
*/
|
|
|
2f13d7 |
if (!payloadfmt) return rc;
|
|
|
2f13d7 |
|
|
|
2f13d7 |
- if (rstreq(payloadfmt, "clon")) return rc;
|
|
|
2f13d7 |
-
|
|
|
2f13d7 |
if (!rstreq(payloadfmt, "cpio")) {
|
|
|
2f13d7 |
char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
|
|
|
2f13d7 |
if (payloadfmt && rstreq(payloadfmt, "drpm")) {
|
|
|
2f13d7 |
diff --git a/lib/fsm.c b/lib/fsm.c
|
|
|
2f13d7 |
index 711f553d3..6972602e0 100644
|
|
|
2f13d7 |
--- a/lib/fsm.c
|
|
|
2f13d7 |
+++ b/lib/fsm.c
|
|
|
bd9c00 |
@@ -17,7 +17,6 @@
|
|
|
bd9c00 |
#include <rpm/rpmts.h>
|
|
|
bd9c00 |
#include <rpm/rpmlog.h>
|
|
|
bd9c00 |
#include <rpm/rpmmacro.h>
|
|
|
bd9c00 |
-#include <rpm/rpmlib.h>
|
|
|
2f13d7 |
|
|
|
2f13d7 |
#include "rpmio/rpmio_internal.h" /* fdInit/FiniDigest */
|
|
|
bd9c00 |
#include "fsm.h"
|
|
|
bd9c00 |
@@ -869,6 +868,24 @@ static rpmfi fsmIterFini(rpmfi fi, struct diriter_s *di)
|
|
|
bd9c00 |
return rpmfiFree(fi);
|
|
|
bd9c00 |
}
|
|
|
bd9c00 |
|
|
|
bd9c00 |
+static int fiIterator(rpmPlugins plugins, FD_t payload, rpmfiles files, rpmfi *fi)
|
|
|
bd9c00 |
+{
|
|
|
bd9c00 |
+ rpmRC plugin_rc = rpmpluginsCallFsmFileArchiveReader(plugins, payload, files, fi);
|
|
|
bd9c00 |
+ switch (plugin_rc) {
|
|
|
bd9c00 |
+ case RPMRC_PLUGIN_CONTENTS:
|
|
|
bd9c00 |
+ if (*fi == NULL)
|
|
|
bd9c00 |
+ return RPMERR_BAD_MAGIC;
|
|
|
bd9c00 |
+ return RPMRC_OK;
|
|
|
bd9c00 |
+ case RPMRC_OK:
|
|
|
bd9c00 |
+ *fi = rpmfiNewArchiveReader(payload, files, RPMFI_ITER_READ_ARCHIVE);
|
|
|
bd9c00 |
+ if (*fi == NULL)
|
|
|
bd9c00 |
+ return RPMERR_BAD_MAGIC;
|
|
|
bd9c00 |
+ return RPMRC_OK;
|
|
|
bd9c00 |
+ default:
|
|
|
bd9c00 |
+ return RPMRC_FAIL;
|
|
|
bd9c00 |
+ }
|
|
|
bd9c00 |
+}
|
|
|
bd9c00 |
+
|
|
|
bd9c00 |
int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
bd9c00 |
rpmpsm psm, char ** failedFile)
|
|
|
bd9c00 |
{
|
|
|
bd9c00 |
@@ -886,13 +903,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
2f13d7 |
struct filedata_s *fdata = xcalloc(fc, sizeof(*fdata));
|
|
|
2f13d7 |
struct filedata_s *firstlink = NULL;
|
|
|
bd9c00 |
struct diriter_s di = { -1, -1 };
|
|
|
2f13d7 |
- Header h = rpmteHeader(te);
|
|
|
2f13d7 |
- const char *payloadfmt = headerGetString(h, RPMTAG_PAYLOADFORMAT);
|
|
|
2f13d7 |
- int cpio = 1;
|
|
|
2f13d7 |
-
|
|
|
2f13d7 |
- if (payloadfmt && rstreq(payloadfmt, "clon")) {
|
|
|
2f13d7 |
- cpio = 0;
|
|
|
2f13d7 |
- }
|
|
|
bd9c00 |
|
|
|
2f13d7 |
/* transaction id used for temporary path suffix while installing */
|
|
|
2f13d7 |
rasprintf(&tid, ";%08x", (unsigned)rpmtsGetTid(ts));
|
|
|
bd9c00 |
@@ -927,12 +937,9 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
2f13d7 |
if (rc)
|
|
|
2f13d7 |
goto exit;
|
|
|
2f13d7 |
|
|
|
2f13d7 |
- if (cpio) {
|
|
|
bd9c00 |
- fi = fsmIter(payload, files,
|
|
|
bd9c00 |
- payload ? RPMFI_ITER_READ_ARCHIVE : RPMFI_ITER_FWD, &di);
|
|
|
2f13d7 |
- } else {
|
|
|
2f13d7 |
- fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
|
|
bd9c00 |
- }
|
|
|
bd9c00 |
+ rc = fiIterator(plugins, payload, files, &fi);
|
|
|
bd9c00 |
+ if (rc)
|
|
|
bd9c00 |
+ goto exit;
|
|
|
bd9c00 |
|
|
|
bd9c00 |
if (fi == NULL) {
|
|
|
bd9c00 |
rc = RPMERR_BAD_MAGIC;
|
|
|
bd9c00 |
@@ -956,7 +963,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
bd9c00 |
int mayopen = 0;
|
|
|
bd9c00 |
int fd = -1;
|
|
|
bd9c00 |
|
|
|
bd9c00 |
- if (!cpio && di.dirfd >= 0)
|
|
|
bd9c00 |
+ if (di.dirfd >= 0)
|
|
|
bd9c00 |
fsmClose(&di.dirfd);
|
|
|
bd9c00 |
rc = ensureDir(plugins, rpmfiDN(fi), 0,
|
|
|
bd9c00 |
(fp->action == FA_CREATE), 0, &di.dirfd);
|
|
|
bd9c00 |
@@ -1075,16 +1082,13 @@ setmeta:
|
|
|
bd9c00 |
rc = fx;
|
|
|
2f13d7 |
|
|
|
bd9c00 |
/* If all went well, commit files to final destination */
|
|
|
bd9c00 |
- if (cpio) {
|
|
|
bd9c00 |
- fi = fsmIter(NULL, files, RPMFI_ITER_FWD, &di);
|
|
|
bd9c00 |
- } else {
|
|
|
bd9c00 |
- fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
|
|
bd9c00 |
- }
|
|
|
bd9c00 |
+ fi = fsmIter(NULL, files, RPMFI_ITER_FWD, &di);
|
|
|
bd9c00 |
+
|
|
|
bd9c00 |
while (!rc && (fx = rpmfiNext(fi)) >= 0) {
|
|
|
bd9c00 |
struct filedata_s *fp = &fdata[fx];
|
|
|
2f13d7 |
|
|
|
bd9c00 |
if (!fp->skip) {
|
|
|
bd9c00 |
- if (!cpio && di.dirfd >= 0)
|
|
|
bd9c00 |
+ if (di.dirfd >= 0)
|
|
|
bd9c00 |
fsmClose(&di.dirfd);
|
|
|
bd9c00 |
if (!rc)
|
|
|
bd9c00 |
rc = ensureDir(NULL, rpmfiDN(fi), 0, 0, 0, &di.dirfd);
|
|
|
2f13d7 |
diff --git a/plugins/reflink.c b/plugins/reflink.c
|
|
|
2f13d7 |
index 7dda06d8e..d5e6db27a 100644
|
|
|
2f13d7 |
--- a/plugins/reflink.c
|
|
|
2f13d7 |
+++ b/plugins/reflink.c
|
|
|
2f13d7 |
@@ -54,6 +54,7 @@ struct reflink_state_s {
|
|
|
2f13d7 |
FD_t fd;
|
|
|
2f13d7 |
rpmfiles files;
|
|
|
2f13d7 |
inodeIndexHash inodeIndexes;
|
|
|
2f13d7 |
+ int transcoded;
|
|
|
2f13d7 |
};
|
|
|
2f13d7 |
|
|
|
2f13d7 |
typedef struct reflink_state_s * reflink_state;
|
|
|
2f13d7 |
@@ -116,12 +117,8 @@ static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
|
|
|
2f13d7 |
break;
|
|
|
2f13d7 |
}
|
|
|
2f13d7 |
rpmlog(RPMLOG_DEBUG, _("reflink: *is* transcoded\n"));
|
|
|
2f13d7 |
- Header h = rpmteHeader(te);
|
|
|
2f13d7 |
+ state->transcoded = 1;
|
|
|
2f13d7 |
|
|
|
2f13d7 |
- /* replace/add header that main fsm.c can read */
|
|
|
2f13d7 |
- headerDel(h, RPMTAG_PAYLOADFORMAT);
|
|
|
2f13d7 |
- headerPutString(h, RPMTAG_PAYLOADFORMAT, "clon");
|
|
|
2f13d7 |
- headerFree(h);
|
|
|
2f13d7 |
state->files = rpmteFiles(te);
|
|
|
2f13d7 |
/* tail of file contains offset_table, offset_checksums then magic */
|
|
|
2f13d7 |
if (Fseek(state->fd, -(sizeof(rpm_loff_t) * 2 + sizeof(extents_magic_t)), SEEK_END) < 0) {
|
|
|
2f13d7 |
@@ -350,10 +347,21 @@ static rpmRC reflink_fsm_file_install(rpmPlugin plugin, rpmfi fi, const char* pa
|
|
|
2f13d7 |
return RPMRC_OK;
|
|
|
2f13d7 |
}
|
|
|
2f13d7 |
|
|
|
2f13d7 |
+static rpmRC reflink_fsm_file_archive_reader(rpmPlugin plugin, FD_t payload,
|
|
|
2f13d7 |
+ rpmfiles files, rpmfi *fi) {
|
|
|
2f13d7 |
+ reflink_state state = rpmPluginGetData(plugin);
|
|
|
2f13d7 |
+ if(state->transcoded) {
|
|
|
2f13d7 |
+ *fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
|
|
2f13d7 |
+ return RPMRC_PLUGIN_CONTENTS;
|
|
|
2f13d7 |
+ }
|
|
|
2f13d7 |
+ return RPMRC_OK;
|
|
|
2f13d7 |
+}
|
|
|
2f13d7 |
+
|
|
|
2f13d7 |
struct rpmPluginHooks_s reflink_hooks = {
|
|
|
2f13d7 |
.init = reflink_init,
|
|
|
2f13d7 |
.cleanup = reflink_cleanup,
|
|
|
2f13d7 |
.psm_pre = reflink_psm_pre,
|
|
|
2f13d7 |
.psm_post = reflink_psm_post,
|
|
|
2f13d7 |
.fsm_file_install = reflink_fsm_file_install,
|
|
|
2f13d7 |
+ .fsm_file_archive_reader = reflink_fsm_file_archive_reader,
|
|
|
2f13d7 |
};
|
|
|
2f13d7 |
--
|
|
|
2f13d7 |
2.35.1
|
|
|
2f13d7 |
|