Merge lp:~jamesodhunt/upstart/check-for-overlayfs into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1560
Proposed branch: lp:~jamesodhunt/upstart/check-for-overlayfs
Merge into: lp:upstart
Diff against target: 191 lines (+156/-3)
4 files modified
ChangeLog (+13/-1)
test/Makefile.am (+14/-1)
test/test_util_common.c (+1/-1)
test/tests/test_util_check_env.c (+128/-0)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/check-for-overlayfs
Reviewer Review Type Date Requested Status
Steve Langasek Needs Fixing
Review via email: mp+191393@code.launchpad.net

Description of the change

* test/tests/test_util_check_env.c: New test to look for
  overlayfs filesystems which could cause tests to fail.
* test/Makefile.am: Added test_util_check_env meta-test.
* test/test_util_common.c: Formatting.

This branch introduces a new meta-test that currently checks for overlayfs. It will produce a warning that tests will probably fail (due to bug LP:#882147) but does not actually abort the test run since:

- the invoker may know better whether a particular FS could cause problems for the tests.
- overlayfs may one day get fixed so hard-failing would be incorrect behaviour.

Note that the new test will be run before any other test. Further, note that since the overlayfs check is a separate test, if an individual test is run in an overlayfs environment, the invoker may be unaware of the strange resultant test failures. However, having a separate test does mean that we avoid linking every test against libnih-dbus et al.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

does not merge cleanly, please sync with trunk and resubmit.

review: Needs Fixing
Revision history for this message
Steve Langasek (vorlon) wrote :

> * Returns: TRUE if any mount point is using overlayfs, else FALSE.

Why warn about *any* overlayfs? Shouldn't we only care about whether the path to our temp directory is affected by overlayfs?

Revision history for this message
James Hunt (jamesodhunt) wrote :

Ok branch updated.

Revision history for this message
Steve Langasek (vorlon) wrote :

Since we're checking the type of a single mountpoint, we should be able to use statfs instead of walking around in /proc/self/mounts. E.g.:

        struct statfs statbuf;

        /* Create a file in the temporary work area */
        TEST_FILENAME (path);
        fclose (fopen (path, "w"));

        assert0 (statfs (path, &statbuf));

        if (statbuf.f_type == OVERLAYFS_SUPER_MAGIC) {
                nih_warn ("Mountpoint for '%s' (needed by the Upstart tests) is an overlayfs "
                                        "filesystem, which does not support inotify.",
                                        path);
                found = TRUE;
        }

        assert0 (unlink (path));

        return found;

It seems that the linux-kernel-headers package does not currently export a define for OVERLAYFS_SUPER_MAGIC, which is an oversight. We can copy this define from the kernel source for now, since it shouldn't change, and ask the kernel team to have it properly exported.

#define OVERLAYFS_SUPER_MAGIC 0x794c764f

What do you think of this approach?

Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Steve,

Yes, that would clearly be more efficient, but I'm not wholly convinced we need to do this since the current approach is simple, it works and we only call this test-only function once anyway. Additionally, the current approach avoids the need to retain the '#ifndef OVERLAYFS_SUPER_MAGIC' forever to handle non-Ubuntu systems.

I've raised bug 1247769 on the kernel headers for the missing define though.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-10-04 21:34:25 +0000
+++ ChangeLog 2013-10-17 08:19:01 +0000
@@ -1,4 +1,16 @@
12013-01-04 Steve Langasek <steve.langasek@ubuntu.com12013-10-17 James Hunt <james.hunt@ubuntu.com>
2
3 * test/tests/test_util_check_env.c:
4 - check_for_overlayfs(): Only consider temporary work area.
5
62013-10-16 James Hunt <james.hunt@ubuntu.com>
7
8 * test/tests/test_util_check_env.c: New test to look for
9 overlayfs filesystems which could cause tests to fail.
10 * test/Makefile.am: Added test_util_check_env meta-test.
11 * test/test_util_common.c: Formatting.
12
132013-10-04 Steve Langasek <steve.langasek@ubuntu.com
214
3 * extra/upstart-local-bridge.c: use SOCKET_PATH in our event15 * extra/upstart-local-bridge.c: use SOCKET_PATH in our event
4 environment, instead of clobbering PATH. (LP: #1235480)16 environment, instead of clobbering PATH. (LP: #1235480)
517
=== modified file 'test/Makefile.am'
--- test/Makefile.am 2013-06-25 09:19:05 +0000
+++ test/Makefile.am 2013-10-17 08:19:01 +0000
@@ -18,4 +18,17 @@
18 -I$(top_srcdir)/intl18 -I$(top_srcdir)/intl
1919
20check_LIBRARIES = libtest_util_common.a20check_LIBRARIES = libtest_util_common.a
21libtest_util_common_a_SOURCES = test_util_common.c test_util_common.h21libtest_util_common_a_SOURCES = \
22 test_util_common.c \
23 test_util_common.h
24
25TESTS = test_util_check_env
26check_PROGRAMS = $(TESTS)
27
28.PHONY: tests
29tests: $(check_PROGRAMS)
30
31test_util_check_env_SOURCES = tests/test_util_check_env.c
32test_util_check_env_LDADD = \
33 libtest_util_common.a \
34 $(NIH_LIBS)
2235
=== modified file 'test/test_util_common.c'
--- test/test_util_common.c 2013-10-02 08:59:20 +0000
+++ test/test_util_common.c 2013-10-17 08:19:01 +0000
@@ -162,7 +162,7 @@
162 * within a reasonable period of time.162 * within a reasonable period of time.
163 */163 */
164 for (i = 0; i < loops; i++) {164 for (i = 0; i < loops; i++) {
165 sleep (1);165 sleep (1);
166166
167 RUN_COMMAND (NULL, cmd, &output, &lines);167 RUN_COMMAND (NULL, cmd, &output, &lines);
168168
169169
=== added directory 'test/tests'
=== added file 'test/tests/test_util_check_env.c'
--- test/tests/test_util_check_env.c 1970-01-01 00:00:00 +0000
+++ test/tests/test_util_check_env.c 2013-10-17 08:19:01 +0000
@@ -0,0 +1,128 @@
1/* upstart
2 *
3 * test_util_check_env.c - meta test to ensure environment sane for
4 * running tests.
5 *
6 * Copyright © 2013 Canonical Ltd.
7 * Author: James Hunt <james.hunt@canonical.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <sys/stat.h>
26#include <limits.h>
27#include <unistd.h>
28#include <mntent.h>
29
30#include <nih/string.h>
31#include <nih/test.h>
32#include <nih/logging.h>
33
34#include "test_util_common.h"
35
36/**
37 * check_for_overlayfs:
38 *
39 * Determine if the mount point used by the tests for creating temporary
40 * files is using overlayfs.
41 *
42 * Returns: TRUE if temporary work area is on overlayfs, else FALSE.
43 **/
44int
45check_for_overlayfs (void)
46{
47 struct stat statbuf;
48 char path[PATH_MAX];
49 const char *fs = "overlayfs";
50 unsigned int maj;
51 unsigned int min;
52 const char *mounts = "/proc/self/mounts";
53 FILE *mtab;
54 struct mntent *mnt;
55 int found = FALSE;
56
57 /* Create a file in the temporary work area */
58 TEST_FILENAME (path);
59 fclose (fopen (path, "w"));
60
61 /* Check it exits */
62 assert0 (stat (path, &statbuf));
63
64 /* Extract device details */
65 maj = major (statbuf.st_dev);
66 min = minor (statbuf.st_dev);
67
68 mtab = fopen (mounts, "r");
69 TEST_NE_P (mtab, NULL);
70
71 /* Look through mount table */
72 while ((mnt = getmntent (mtab))) {
73 unsigned int mount_maj;
74 unsigned int mount_min;
75
76 assert0 (stat (mnt->mnt_dir, &statbuf));
77 mount_maj = major (statbuf.st_dev);
78 mount_min = minor (statbuf.st_dev);
79
80 if (! strcmp (mnt->mnt_type, fs) && mount_maj == maj && mount_min == min) {
81 found = TRUE;
82 nih_warn ("Mountpoint '%s' (needed by the Upstart tests) is an '%s' "
83 "filesystem which does not support inotify.",
84 mnt->mnt_dir,
85 fs);
86 goto out;
87 }
88 }
89
90out:
91 fclose (mtab);
92 assert0 (unlink (path));
93
94 return found;
95}
96
97/**
98 * test_checks:
99 *
100 * Perform any checks necessary before real tests are run.
101 **/
102void
103test_checks (void)
104{
105 TEST_GROUP ("test environment");
106
107 /*
108 * Warn (*) if overlayfs detected.
109 *
110 * (*) - Don't fail in the hope that one day someone might fix
111 * overlayfs.
112 */
113 TEST_FEATURE ("checking for overlayfs");
114 if (check_for_overlayfs ()) {
115 nih_warn ("Found overlayfs mounts");
116 nih_warn ("This environment will probably cause tests to fail mysteriously!!");
117 nih_warn ("See bug LP:#882147 for further details.");
118 }
119}
120
121int
122main (int argc,
123 char *argv[])
124{
125 test_checks ();
126
127 return 0;
128}

Subscribers

People subscribed via source and target branches