[ostree] repo: Move the scanning hardlinks optimization out of prepare_transaction
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] repo: Move the scanning hardlinks optimization out of prepare_transaction
- Date: Sat, 7 Sep 2013 00:32:45 +0000 (UTC)
commit bd2948e9641b4179d53ee5763bd3effb1617ca5a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Sep 6 18:51:54 2013 -0400
repo: Move the scanning hardlinks optimization out of prepare_transaction
This is just a terrible API to have. Make the scanning a separate method,
and document it as an optimization.
doc/ostree-sections.txt | 1 +
src/libostree/ostree-repo-commit.c | 48 +++++++++++++++++++++++++++--------
src/libostree/ostree-repo-pull.c | 2 +-
src/libostree/ostree-repo.h | 5 +++-
src/ostree/ot-builtin-commit.c | 5 +++-
src/ostree/ot-builtin-pull-local.c | 2 +-
6 files changed, 48 insertions(+), 15 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index f5abbd5..1e4a6f5 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -64,6 +64,7 @@ ostree_repo_copy_config
ostree_repo_get_parent
ostree_repo_write_config
OstreeRepoTransactionStats
+ostree_repo_scan_hardlinks
ostree_repo_prepare_transaction
ostree_repo_commit_transaction
ostree_repo_abort_transaction
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 8b69e48..32b0e2e 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -525,9 +525,45 @@ devino_cache_lookup (OstreeRepo *self,
}
/**
+ * ostree_repo_scan_hardlinks:
+ * @self: An #OstreeRepo
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * When ostree builds a mutable tree from directory like in
+ * ostree_repo_write_directory_to_mtree(), it has to scan all files that you
+ * pass in and compute their checksums. If your commit contains hardlinks from
+ * ostree's existing repo, ostree can build a mapping of device numbers and
+ * inodes to their checksum.
+ *
+ * There is an upfront cost to creating this mapping, as this will scan the
+ * entire objects directory. If your commit is composed of mostly hardlinks to
+ * existing ostree objects, then this will speed up considerably, so call it
+ * before you call ostree_write_directory_to_mtree() or similar.
+ */
+gboolean
+ostree_repo_scan_hardlinks (OstreeRepo *self,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ g_return_val_if_fail (self->in_transaction == TRUE, FALSE);
+
+ if (!self->loose_object_devino_hash)
+ self->loose_object_devino_hash = g_hash_table_new_full (devino_hash, devino_equal, g_free, g_free);
+ g_hash_table_remove_all (self->loose_object_devino_hash);
+ if (!scan_loose_devino (self, self->loose_object_devino_hash, cancellable, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+/**
* ostree_repo_prepare_transaction:
* @self: An #OstreeRepo
- * @enable_commit_hardlink_scan:
* @out_transaction_resume: (allow-none) (out): Whether this transaction
* is resuming from a previous one.
* @cancellable: Cancellable
@@ -543,7 +579,6 @@ devino_cache_lookup (OstreeRepo *self,
*/
gboolean
ostree_repo_prepare_transaction (OstreeRepo *self,
- gboolean enable_commit_hardlink_scan,
gboolean *out_transaction_resume,
GCancellable *cancellable,
GError **error)
@@ -575,15 +610,6 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
cancellable, error))
goto out;
- if (enable_commit_hardlink_scan)
- {
- if (!self->loose_object_devino_hash)
- self->loose_object_devino_hash = g_hash_table_new_full (devino_hash, devino_equal, g_free, g_free);
- g_hash_table_remove_all (self->loose_object_devino_hash);
- if (!scan_loose_devino (self, self->loose_object_devino_hash, cancellable, error))
- goto out;
- }
-
ret = TRUE;
if (out_transaction_resume)
*out_transaction_resume = ret_transaction_resume;
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index 0a42e3f..d557e42 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1286,7 +1286,7 @@ ostree_repo_pull (OstreeRepo *self,
}
}
- if (!ostree_repo_prepare_transaction (pull_data->repo, FALSE, &pull_data->transaction_resuming,
+ if (!ostree_repo_prepare_transaction (pull_data->repo, &pull_data->transaction_resuming,
cancellable, error))
goto out;
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 882e306..8a4c75d 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -112,8 +112,11 @@ struct _OstreeRepoTransactionStats {
GType ostree_repo_transaction_stats_get_type (void);
+gboolean ostree_repo_scan_hardlinks (OstreeRepo *self,
+ GCancellable *cancellable,
+ GError **error);
+
gboolean ostree_repo_prepare_transaction (OstreeRepo *self,
- gboolean enable_commit_hardlink_scan,
gboolean *out_transaction_resume,
GCancellable *cancellable,
GError **error);
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 80d0e50..d9ed29d 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -290,7 +290,10 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
goto out;
}
- if (!ostree_repo_prepare_transaction (repo, opt_link_checkout_speedup, NULL, cancellable, error))
+ if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
+ goto out;
+
+ if (opt_link_checkout_speedup && !ostree_repo_scan_hardlinks (repo, cancellable, error))
goto out;
mtree = ostree_mutable_tree_new ();
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
index 98ba6cd..e435457 100644
--- a/src/ostree/ot-builtin-pull-local.c
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -230,7 +230,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable
}
}
- if (!ostree_repo_prepare_transaction (data->dest_repo, FALSE, &transaction_resuming,
+ if (!ostree_repo_prepare_transaction (data->dest_repo, &transaction_resuming,
cancellable, error))
goto out;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]