Skip to content

Commit 3a1d6d3

Browse files
committed
compat: test and patch for __counted_by
Unfortunately, the "attribute name" variable type only works with very recent coccinelle versions (>=1.1.1). So add a hint about that in the README.
1 parent 85afbf8 commit 3a1d6d3

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Since version 9.0.20, DRBD has been using a kernel backwards compatibility syste
3838
based on [Coccinelle](https://github.com/coccinelle/coccinelle) semantic patches.
3939
While this has many advantages, it also makes it a little harder for "casual"
4040
developers to build DRBD from the git sources. The problem is that we require a
41-
very recent version of `spatch` (at least 1.0.8 at time of writing), and most
41+
very recent version of `spatch` (at least 1.1.1 at time of writing), and most
4242
distributions only have relatively old versions in their repositories.
4343

4444
## From git
@@ -48,10 +48,9 @@ For users wishing to build DRBD from its git sources, here are a few options:
4848
chances are you won't even have to use any of the compat features, which
4949
means you won't require compatibility patches and in turn don't need spatch
5050
installed.
51-
2. On Ubuntu 18.04 and newer, use a recent spatch version from the
52-
[Coccinelle PPA](https://launchpad.net/~npalix/+archive/ubuntu/coccinelle).
53-
This provides (at time of writing) version 1.0.8, which is recent enough to
54-
build DRBD.
51+
2. Fedora >=39 packages Coccinelle 1.1.1, which is recent enough to build DRBD. **Warning**: while
52+
Ubuntu also ships Coccinelle with supposedly the same version number (1.1.1), this version
53+
is *not* able to build DRBD.
5554
3. Build and install spatch from source. This will also give you a version that
5655
is recent enough to build DRBD.
5756

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@@
2+
type T;
3+
identifier s, x;
4+
attribute name __counted_by;
5+
@@
6+
struct s {
7+
...
8+
T x
9+
- __counted_by(...)
10+
;
11+
...
12+
};

drbd/drbd-kernel-compat/gen_patch_names.c

+3
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ int main(int argc, char **argv)
605605
patch(1, "need_recalc_sigpending", false, true,
606606
COMPAT_NEED_RECALC_SIGPENDING, "need");
607607

608+
patch(1, "counted_by", true, false,
609+
COMPAT_HAVE_COUNTED_BY, "present");
610+
608611
/* #define BLKDEV_ISSUE_ZEROOUT_EXPORTED */
609612
/* #define BLKDEV_ZERO_NOUNMAP */
610613

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* { "version": "v6.4", "commit": "dd06e72e68bcb4070ef211be100d2896e236c8fb", "comment": "add __counted_by macro", "author": "Kees Cook <[email protected]>", "date": "Wed May 17 12:08:44 2023 -0700" } */
2+
3+
#include <linux/compiler_attributes.h>
4+
5+
struct foo {
6+
int a;
7+
int b[] __counted_by(a);
8+
};

0 commit comments

Comments
 (0)