|
1 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later |
2 | 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
3 | 3 | * Copyright (c) 2009-2016 Cyril Hrubis [email protected] |
| 4 | + * Copyright (c) Linux Test Project, 2020-2025 |
4 | 5 | */ |
5 | 6 |
|
6 | 7 | #ifndef TST_KVERCMP_H__ |
7 | 8 | #define TST_KVERCMP_H__ |
8 | 9 |
|
9 | | -/* |
| 10 | +/** |
| 11 | + * tst_kvcmp() - Compare given kernel version with kernel in string. |
| 12 | + * |
| 13 | + * @cur_kver: Kernel version string (struct utsname.release). |
| 14 | + * @r1: Major kernel version. |
| 15 | + * @r2: Minor kernel version. |
| 16 | + * @r3: Kernel patch level. |
| 17 | + * |
| 18 | + * Everything after first three version numbers till the end of the string is |
| 19 | + * ignored. |
| 20 | + * |
10 | 21 | * The same as tst_kvercmp() but running kernel version is passed as parameter |
11 | 22 | * instead of utilizing uname(). |
| 23 | + * |
| 24 | + * Return: Negative if older, 0 if the same and positive if newer. |
12 | 25 | */ |
13 | 26 | int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3); |
14 | 27 |
|
15 | | -/* |
16 | | - * Parsers string into three integer version. |
| 28 | +/** |
| 29 | + * tst_parse_kver() - Parses a version string into three integers. |
| 30 | + * |
| 31 | + * @str_kver: Kernel version string (struct utsname.release). |
| 32 | + * @v1: Major kernel version. |
| 33 | + * @v2: Minor kernel version. |
| 34 | + * @v3: Kernel patch level. |
| 35 | + * |
| 36 | + * Everything after first three version numbers till the end of the string is |
| 37 | + * ignored. |
| 38 | + * |
| 39 | + * Return: 0 on success, 1 on error. |
17 | 40 | */ |
18 | 41 | int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3); |
19 | 42 |
|
20 | | -/* |
21 | | - * Returns distribution name parsed from kernel version string or NULL. |
| 43 | +/** |
| 44 | + * tst_kvcmp_distname() - Get the distribution name from kernel version string. |
| 45 | + * |
| 46 | + * @cur_kver: Kernel version string (struct utsname.release). |
| 47 | + * |
| 48 | + * Return: The distribution name parsed from kernel version string or NULL. |
22 | 49 | */ |
23 | 50 | const char *tst_kvcmp_distname(const char *cur_kver); |
24 | 51 |
|
25 | | -/* |
26 | | - * Compares versions up to five version numbers long. |
| 52 | +/** |
| 53 | + * tst_kvexcmp() - Compares versions up to five version numbers long. |
| 54 | + * @tst_exv: The tested kernel version string (struct utsname.release). |
| 55 | + * @cur_kver: The current version in string (struct utsname.release). |
| 56 | + * |
| 57 | + * The return value is similar to the :man3:`strcmp` function, i.e. zero means |
| 58 | + * equal, negative value means that the kernel is older than the expected value |
| 59 | + * and positive means that it's newer. |
| 60 | + * |
| 61 | + * Return: negative if older, 0 if the same and positive if newer. |
27 | 62 | */ |
28 | 63 | int tst_kvexcmp(const char *tst_exv, const char *cur_kver); |
29 | 64 |
|
30 | | -/* |
31 | | - * Compare given kernel version with currently running kernel. |
| 65 | +/** |
| 66 | + * tst_kvercmp() - Compare a kernel version against currently running kernel. |
| 67 | + * |
| 68 | + * @r1: Major kernel version. |
| 69 | + * @r2: Minor kernel version. |
| 70 | + * @r3: Kernel patch level. |
| 71 | + * |
| 72 | + * Parse the output from :man2:`uname` and compare it to the passed values. |
| 73 | + * This is shortcut for calling tst_kvcmp() with ``uname -r`` as str_kver. |
32 | 74 | * |
33 | | - * Returns negative if older, 0 if the same and positive if newer. |
| 75 | + * Return: Negative if older, 0 if the same and positive if newer. |
34 | 76 | */ |
35 | 77 | int tst_kvercmp(int r1, int r2, int r3); |
36 | 78 |
|
| 79 | +/** |
| 80 | + * struct tst_kern_exv - describe vendor kernel. |
| 81 | + * |
| 82 | + * @dist_name: A distribution name, e.g. "SLES", "RHEL9", "UBUNTU". |
| 83 | + * @extra_ver: A vendor kernel version to check, e.g. "5.14.0-441". |
| 84 | + */ |
37 | 85 | struct tst_kern_exv { |
38 | 86 | char *dist_name; |
39 | 87 | char *extra_ver; |
40 | 88 | }; |
41 | 89 |
|
| 90 | +/** |
| 91 | + * tst_kvercmp2() - Compare given *distro* kernel version with the currently running kernel. |
| 92 | + * |
| 93 | + * @r1: Major kernel version. |
| 94 | + * @r2: Minor kernel version. |
| 95 | + * @r3: Kernel patch level. |
| 96 | + * @vers: A {} terminated array of :ref:`struct tst_kern_exv`. |
| 97 | + * |
| 98 | + * Attempts to look up a distro specific kernel version from the struct |
| 99 | + * tst_kern_exv table first and if no match is found falls back to the version |
| 100 | + * passed in r1, r2, r3 (see tst_kvercmp()). |
| 101 | + * |
| 102 | + * The distribution name is detected either from the kernel release string e.g. |
| 103 | + * el9 is mapped to RHEL9 or as a capitalized value of the ``ID=`` variable from |
| 104 | + * ``/etc/os-release``. |
| 105 | + * |
| 106 | + * Return: Negative if older, 0 if the same and positive if newer. |
| 107 | + */ |
42 | 108 | int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers); |
43 | 109 |
|
44 | 110 | #endif /* TST_KVERCMP_H__ */ |
0 commit comments