Commit Graph

3146 Commits

Author SHA1 Message Date
Colin Walters
9380dbb14d lib: Add "open dfd iter handling noent" helper, port tree-wide
Follow up to a previous patch that addressed a double-close; I
realized we already had a helper for doing "open dfd iter, do nothing
if we get ENOENT".  Raise it to libotuil, and port all consumers.

Closes: #863
Approved by: jlebon
2017-05-16 18:39:19 +00:00
Colin Walters
90cd7f7234 tree-wide: Add a few missing O_CLOEXEC
I noticed an instance of this while working on https://github.com/ostreedev/ostree/pull/861
Which apparently I cargo-culted into the new system generator bits.
Let's break this out as a small concise change.

Closes: #866
Approved by: jlebon
2017-05-16 17:34:46 +00:00
Colin Walters
30705889cb Switch to using a systemd generator for /var
If one wants to set up a mount for `/var` in `/etc/fstab`, it
won't be mounted since `ostree-prepare-root` set up a bind mount for
`/var` to `/sysroot/ostree/$stateroot/var`, and systemd will take
the already extant mount over what's in `/etc/fstab`.

There are a few options to fix this, but what I settled on is parsing
`/etc/fstab` in a generator (exactly like `systemd-fstab-generator` does),
except here we look for an explicit mount for `/var`, and if one *isn't* found,
synthesize the default ostree mount to the stateroot. Another nice property is
that if an admin creates a `var.mount` unit in `/etc` for example, that will
also override our mount.

Note that today ostree doesn't hard depend on systemd, so this behavior only
kicks in if we're built with systemd *and* libmount support (for parsing
`/etc/fstab`).  I didn't really test that case though.

Initially I started writing this as a "pure libc" program, but at one point
decided to use `libostree.so` to find the booted deployment. That didn't work
out because `/boot` wasn't necessarily mounted and hence we couldn't find the
bootloader config. A leftover artifact from this is that the generator code
calls into libostree via the "cmd private" infrastructure. But it's an easy way
to share code, and doesn't hurt.

Closes: #859
Approved by: jlebon
2017-05-16 16:13:05 +00:00
Colin Walters
d815ba2a81 switchroot/remount: Check mount status before remounting, be verbose
By checking the mount status, we avoid remounting things if we don't
need to.  And printing a single line per mount helps debugging when
things go wrong.

Closes: #859
Approved by: jlebon
2017-05-16 16:13:05 +00:00
Colin Walters
f21f500e40 switchroot/remount: Trim set of remounted filesystems
I really have no idea what I was thinking with that list of mount points. It
seems arbitrary. Sadly `git log` doesn't help, and there's no comments.

Basically, the only mounts we should care about are those that libostree
creates. Which are just `/sysroot` and `/var`. Systemd will handle the other
things like `/tmp`, it's not our job, and we shouldn't touch them.

Closes: #859
Approved by: jlebon
2017-05-16 16:13:05 +00:00
Colin Walters
19827a9965 lib/repo: Fix double close()
Should probably change `_take_fd()` to take a pointer and set to `-1`
at some point.

Regression from 8d58ab1002

Closes: #862
Approved by: jlebon
2017-05-16 14:01:24 +00:00
Colin Walters
a5eef45deb lib/remote: Box OstreeRemote if experimental-api
To avoid an introspection warning.  Otherwise, don't box it.

Closes: #858
Approved by: pwithnall
2017-05-16 08:28:47 +00:00
Colin Walters
05d0ee5cbe remount: Drop support for auto-tmpfs-on-var; use systemd.volatile=state
In current systemd, there is:
[systemd-volatile-root](https://www.freedesktop.org/software/systemd/man/systemd-volatile-root.service.html)
which was introduced by [this commit](91214a37ef).

I'd like to make further changes to how we handle `/var`, and I don't
want to reason about the interaction of our "tmpfs var" with too many
other things.

The comment about having "all /var handling in one place" was always inaccurate
given that we rely on systemd for mounting. And in general, I don't want to
duplicate too many things systemd does - it does them well, documents them, etc.

As far as I know, it was basically just Owen who was using this for the GNOME
hardware testing effort, and I'm sure he could easily switch over to
`systemd.volatile=state`.

Closes: #856
Approved by: owtaylor
2017-05-15 18:09:21 +00:00
Jonathan Lebon
23c60cda22 libglnx: bump and use new helper methods
Update submodule: libglnx

Closes: #857
Approved by: cgwalters
2017-05-12 21:02:16 +00:00
Jonathan Lebon
5811d4e8a3 tests/ci-commitmessage-submodules.sh: fix for RHCI
Special-case when this script is run under RHCI, which will try to fetch
the merge commit if possible. Use RHCI_COMMIT instead to refer to the
actual PR/branch HEAD being evaluated.

Use realpath to workaround the developer's git dir being in a symbolic
link.

Closes: #857
Approved by: cgwalters
2017-05-12 21:02:16 +00:00
Colin Walters
a195888b0f lib/checkout: Fix regression in subpath for regular files
This is what caused the merge of
https://github.com/projectatomic/rpm-ostree/pull/652
to blow up, since https://github.com/ostreedev/ostree/pull/848
landed right before we tried to merge it.

When I was writing that PR I remember having an uncertain feeling
since we were doing a `mkdirat` above, but at the time I thought
we'd have test suite coverage...turns out we didn't.

For backwards compatibility, we need to continue to do a `mkdirat` here of the
parent. However...I can't think of a reason anyone would *want* that behavior.
Hence, let's add a special trick - if the destination name is `.`, we skip
`mkdirat()`. That way rpm-ostree for example can open a dfd for `/etc` and avoid
the `mkdir`.

Fold the subpath tests into `test-basic.sh` since it's not worth a separate
file. Add a test case for checking out a file.

Closes: #854
Approved by: jlebon
2017-05-12 14:00:20 +00:00
Colin Walters
b83d509e78 tree-wide: Switch tabs ⭾ in various files over to spaces ␠
As $DEITY intended.

I was reading the `prepare-root.c` code and the indentation damage was
distracting. Squash tabs that have leaked into various places in the code. I
didn't yet touch the `src/libostree` bits as that has higher potential for
conflict.

Closes: #852
Approved by: jlebon
2017-05-11 18:17:26 +00:00
Colin Walters
ce4d21bc17 checkout: Plug a memleak of the state stringbuf
A struct without a cleanup macro is a struct likely to leak.

Closes: #850
Approved by: jlebon
2017-05-11 15:34:51 +00:00
Colin Walters
0177214982 lib/repo: Port more of GPG and summary functions to new code style
These ones were pretty easy, not sure why I didn't do them in an earlier pass.

Closes: #849
Approved by: jlebon
2017-05-11 15:26:49 +00:00
Colin Walters
964ca9d434 repo: Fix double close() in summary generation
Happened to notice this while doing a style port.

Closes: #849
Approved by: jlebon
2017-05-11 15:26:49 +00:00
Colin Walters
e6f17b949d lib/checkout: Optimize checkout by avoiding OstreeRepoFile recusion
Looking at `perf record ostree checkout`, some things stand out; e.g.:

```
+   27.63%     0.07%  ostree   libgio-2.0.so.0.5000.3      [.] g_file_enumerator_iterate
+   22.74%     0.28%  ostree   libostree-1.so.1.0.0        [.] ostree_repo_file_tree_query_child
+   13.74%     0.08%  ostree   libostree-1.so.1.0.0        [.] ot_variant_bsearch_str
```

The GIO abstractions are already fairly heavyweight, and `OstreeRepoFile` mallocs
a lot too.

Make things more efficient here by dropping the GIO bits for reading ostree data -
we just read from the variants directly and iterate over them.  The end result
here is that according to perf we go from ~40% of our time in the kernel to
~70%, and things like `g_file_enumerator_iterate()` drop entirely out of the
hot set.

Closes: #848
Approved by: jlebon
2017-05-11 14:15:54 +00:00
Colin Walters
7896bcbe65 lib/checkout: Move special case for subpath of file to toplevel
Since we now have a cleaner separation of "toplevel checkout prep"
versus "recursive checkout", handle the special case of checking out
a single file at first rather than later.

Prep for future work in optimizing this function more.

Closes: #848
Approved by: jlebon
2017-05-11 14:15:54 +00:00
Colin Walters
986e05e3fd lib/prune: Complete porting to new code style
Only non-mechanical bit here was creating a local autoptr for a bit
where we'd previously done an unref for a struct member.

Closes: #847
Approved by: jlebon
2017-05-11 13:20:38 +00:00
Colin Walters
63497c65f3 checkout/commit: Use glnx_regfile_copy_bytes() if possible
Rather than `g_output_stream_splice()`, where the input is a regular
file.

See https://github.com/GNOME/libglnx/pull/44 for some more information.

I didn't try to measure the performance difference, but seeing the
read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me
when reading strace.

As a bonus, we will again start using reflinks (if available) for `/etc`,
which is a regression from the https://github.com/ostreedev/ostree/pull/797
changes (which before used `glnx_file_copy_at()`).

Also, for the first time we'll use reflinks when doing commits from file-backed
content. This happens in `rpm-ostree compose tree` today for example.

Update submodule: libglnx

Closes: #817
Approved by: jlebon
2017-05-10 15:10:30 +00:00
Colin Walters
05fda71cb1 sysroot: More porting to new code style
This isn't all of this file yet, just doing another chunk.

Closes: #845
Approved by: jlebon
2017-05-10 14:09:42 +00:00
Colin Walters
18c5947c5f diff: Port some to new code style
Continuing to chip away at this.  Using `g_file_enumerator_iterate()`
here helps notably.

I started on the much bigger `ostree_diff_dirs_with_options()` but
it's a lot messier - for later.

Closes: #844
Approved by: jlebon
2017-05-09 18:33:12 +00:00
Colin Walters
bf1a994d85 ci: Move travis scripts from tests/ → ci/
I think tests/ should be just that, ci/ is separate.  Also rename
the files to include "travis" since that's what we use them
for right now.

Closes: #843
Approved by: jlebon
2017-05-09 18:25:13 +00:00
Colin Walters
7c88161044 ci: More flatpak ci fixes
We need our `make install` to override the ostree RPM, so do it all in one txn.
This sort of thing is where a more rigorous model like rdgo/gcontinuous use
becomes better, but we'll hack it with shell for now.

Closes: #824
Approved by: jlebon
2017-05-09 18:17:19 +00:00
Colin Walters
af7fed94ed ci: Extend FAH rootfs for installed tests
These at the moment aren't in a container, and may need space. In the future
overlay2 will help here, we can more easily extend the rootfs.

Closes: #840
Approved by: jlebon
2017-05-09 15:08:26 +00:00
Colin Walters
48d2637e98 tests: Migrate test-pull-many.sh to installed on FAH
`test-pull-many.sh` is was just too slow to be a unit test.  Generating
a bunch of files via shell is slow, the delta generation is slow, etc.
Every developer doesn't need to run it every time.

Somewhat address this by converting it into our installed test framework, which
moves it out of the developer fast paths.  Another advantage to this is
that we can simply reuse the FAH tree content rather than synthesizing
new bits each time.

Closes: #840
Approved by: jlebon
2017-05-09 15:08:26 +00:00
Colin Walters
2800d176bc tests: For installed, s/test-/itest-/ to avoid in-tree name clashes
I want to migrate `test-pull-many.sh` → `itest-pull.sh`, hence not
conflicting with the unit test `test-pull.sh.

Closes: #840
Approved by: jlebon
2017-05-09 15:08:26 +00:00
Colin Walters
86963334bd fsck: Check for refs missing corresponding commit
Just doing this one quickly since it was easy.

Closes: https://github.com/ostreedev/ostree/issues/831

Closes: #841
Approved by: jlebon
2017-05-09 14:05:46 +00:00
Colin Walters
052ba81c03 utils/checksum: Port to new code style
Just happened to be reading this code, it's an easy port.

Closes: #842
Approved by: jlebon
2017-05-09 13:51:12 +00:00
Philip Withnall
50f73cbac3 build: Add -C arguments to some git invocations
This moves the build system a little closer towards being safe for
builddir ≠ srcdir.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #832
Approved by: cgwalters
2017-05-08 18:48:07 +00:00
Philip Withnall
6eac575f21 libostree: Make OstreeRemote a public and internal API
Previously it was static to ostree-repo.c. Make it usable throughout
libostree so it can be used by an upcoming commit, but also expose the
typedef and reference counting functions so that opaque OstreeRemote
pointers can be used by user code, in anticipation of exposing more of
its API publicly in future.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #832
Approved by: cgwalters
2017-05-08 18:48:07 +00:00
Philip Withnall
eeee5a0a1e libostree: Expose $OSTREE_FEATURES in the pkg-config file
This allows consumers of libostree to check at configure time whether it
supports the feature they want.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #832
Approved by: cgwalters
2017-05-08 18:48:07 +00:00
Philip Withnall
c9244b1bb2 build: Add --enable-experimental-api configure option for unstable APIs
There are currently no unstable APIs, but some will be added in
following commits. They will be built and exposed in the libostree
global symbol list iff configured with --enable-experimental-api.

Distributions should not package OSTree with --enable-experimental-api.
This is designed for previewing new APIs on controlled platforms; any of
the APIs hidden behind this option may be changed or removed at any
point.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #832
Approved by: cgwalters
2017-05-08 18:48:07 +00:00
Colin Walters
c7efe01520 Add --enable-installed-tests=exclusive, fix installed case
The major reason to do this is that running tests *both* installed
and uninstalled in our CI is a mostly pointless waste of time.
Particularly given we have a few expensive tests.

We *do* have tests that only run uninstalled (since they require
the source code) like `test-symbols.sh`.

Hence, add `--enable-installed-tests=exclusive` to mean *only* do installed for
most tests.

We'll still have uninstalled coverage via the Travis/Debian configs, and we
could perhaps do another build with a subset of uninstalled tests, but I'm not
really concerned about it.

I'd like to do a renewed push for the InstalledTests model since
I feel it's just fundamentally better.  (`g-d-t-r` kind of sucks,
but then so does the automake runner).

Also while we're here - fix the CI to use the correct context,
which started this mess.

Closes: #837
Approved by: dbnicholson
2017-05-08 18:34:10 +00:00
Dan Nicholson
fa4e4bf4df tests: Look for trivial-httpd in $libexecdir
Since b825aac, trivial-httpd is in $libexecdir/libostree by default and
not available through the ostree runner in PATH. Try to adjust find it
when running the tests installed.

Closes: #837
Approved by: dbnicholson
2017-05-08 18:34:10 +00:00
Dan Nicholson
1fe914755a tests: Install libtest-core.sh with installed tests
Without this, running the installed tests fails dramatically. Remove it
from EXTRA_DIST since dist_installed_test_data takes care of dist.

Closes: #837
Approved by: dbnicholson
2017-05-08 18:34:10 +00:00
Philip Withnall
9690a54e47 tests: Fix regex escaping in test-summary-view.sh
There were some regex special characters in the pattern strings, which I
think were causing the test to fail on some Travis builds due to using
an invalid regex.

Fix that by matching using fixed strings instead. We don’t need regexes
here. Use a new assert_file_has_content_literal to do that for us.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #838
Approved by: cgwalters
2017-05-08 17:36:33 +00:00
Dan Nicholson
4e13361c8e pull: Allow additional HTTP headers for summary fetch
Read the http-headers (a(ss)) option in
ostree_repo_remote_fetch_summary_with_options like
ostree_repo_pull_with_options and add the headers to the fetcher. This
allows things like providing additional authorization headers to the
HTTP requests.

Closes: #839
Approved by: cgwalters
2017-05-08 16:50:45 +00:00
Dan Nicholson
37b8dae2c4 commit: Mark ostree_repo_transaction_set_ref* checksums nullable
Allow GI bindings to delete refs through ostree_repo_transaction_set_ref
and ostree_repo_transaction_set_refspec by setting the checksum to NULL.

Closes: #834
Approved by: cgwalters
2017-05-08 16:35:09 +00:00
Philip Withnall
f3cc0eb25a tests: Add a test for ostree summary --view
This includes a test of the new human-readable key names.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:25 +00:00
Philip Withnall
c1290177a3 ostree: Use #defines for well-known metadata key names
Rather than hard-coding the names as strings. This makes the code a
little more maintainable.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:24 +00:00
Philip Withnall
a946c3d423 ostree: Improve formatting for well-known summary metadata keys
If a summary metadata key is well-known, like ostree.static-deltas, or
ostree.summary.last-modified, format it a little more nicely.

This is especially important for timestamps like last-modified, since
otherwise they’re formatted as a big-endian uint64, which is basically
unusable for the user.

Non-formatted output can still be retrieved using the OSTREE_DUMP_RAW
flag, and the non-formatted key name is always printed for clarity.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:24 +00:00
Philip Withnall
8ea654251a ostree: Add --view mode to ostree summary
This allows a locally generated summary file to be viewed. It accepts
the same arguments as `ostree remote summary` (i.e. --raw).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:24 +00:00
Philip Withnall
015ce7520b libostree: Document endianness of GVariant metadata types
Endianness strikes again.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:24 +00:00
Philip Withnall
9aa8d420cf libostree: Add some additional metadata to the summary file
• Commit timestamps, so it’s easy to work out whether a given commit is
   newer than the one we have locally
 • Summary file timestamp, so it’s easy to work out whether the summary
   file is more up to date than another summary file
 • Summary file expiry time, so clients can work out when they should
   expect the summary file to next be updated, and hence can query for
   it at roughly the right time

The expiry time requires input from the user, so is currently never set
automatically. Programs using libostree can set it if they wish.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #826
Approved by: cgwalters
2017-05-08 00:55:24 +00:00
Sjoerd Simons
e6666fc2e5 repo/commit: Fix memory leak
While running the testsuite under valgrind a small memory leak showed up:

==16487== 65 bytes in 1 blocks are definitely lost in loss record 773 of 1,123
==16487==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==16487==    by 0x6048E08: g_malloc (gmem.c:94)
==16487==    by 0x6062EAE: g_strdup (gstrfuncs.c:363)
==16487==    by 0x54CE3E6: write_object (ostree-repo-commit.c:776)
==16487==    by 0x54CF2D4: ostree_repo_write_metadata (ostree-repo-commit.c:1528)
==16487==    by 0x54CF505: _ostree_repo_write_directory_meta (ostree-repo-commit.c:1712)
==16487==    by 0x54D0AB4: write_dfd_iter_to_mtree_internal (ostree-repo-commit.c:2650)
==16487==    by 0x54D0E2D: ostree_repo_write_dfd_to_mtree (ostree-repo-commit.c:2793)
==16487==    by 0x1190C4: ostree_builtin_commit (ot-builtin-commit.c:474)
==16487==    by 0x11F2EE: ostree_run (ot-main.c:200)
==16487==    by 0x116F32: main (main.c:78)

The reason for this is that ot_checksum_instream_get_string returns a chunk of newly allocated memory which never got freed.

Make actual_checksum something that gets autocleanend and own the memory
assigned to it in all cases.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

Closes: #827
Approved by: pwithnall
2017-05-05 15:31:38 +00:00
Colin Walters
712bf21914 tree-wide: Convert to using autoptr(GString) vs g_string_free(...,TRUE)
If we're freeing the segment, it's basically always better to use
`autoptr()`.  Fewer lines, more reliable, etc.

Noticed an instance of this in the pull code while reviewing a different PR,
decided to do a grep for it and fix it tree wide.

Closes: #836
Approved by: pwithnall
2017-05-05 15:10:51 +00:00
Philip Withnall
bf9772f231 libostree: Ensure progress keys are all always set
If one of the progress keys is set in a pull operation, a ::changed
signal is emitted on the progress object, and the callback for that
could query any of the progress keys — so they all need to be set,
otherwise we get an assertion failure in ostree_async_progress_get() due
to a named key not existing.

Spotted by Dan Nicholson in PR #819.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #835
Approved by: cgwalters
2017-05-05 14:58:03 +00:00
Philip Withnall
f1da7ec300 libostree: Fix potential use of uninitialised memory in progress API
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #835
Approved by: cgwalters
2017-05-05 14:58:03 +00:00
Dan Nicholson
59897f2b84 pull: Fix crash specifying override URL in summary fetch
The summary URL override is looked up with "&s", which directly
exchanges the data to a pointer without allocation. This was causing a
segfault calling ostree_repo_remote_fetch_summary_with_options from
pygobject.

Closes: #829
Approved by: jlebon
2017-05-03 18:08:37 +00:00
Philip Withnall
4c731165bb libostree: Add missing checks for invalid timestamps
g_date_time_new_from_unix_utc() will not always return a valid GDateTime
— if the input timestamp is too big, GDateTime cannot represent it, and
the constructor returns NULL.

Add some missing checks for these situations. We don’t ever expect
timestamps to be this big, but they could be as a result of corruption
or a malicious repository.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #825
Approved by: cgwalters
2017-05-03 15:23:15 +00:00