summaryrefslogtreecommitdiff
path: root/add-a-new-switch-to-control-whether-udev-complies-wi.patch
blob: d2b52d618b37291bb1ffd905814ed2503c952feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From 18c373e2686a9156a701ad440507172ec8bb13a3 Mon Sep 17 00:00:00 2001
From: wangyuhang <wangyuhang27@huawei.com>
Date: Fri, 7 Jul 2023 16:11:01 +0800
Subject: [PATCH] Add a new switch to control whether udev complies with the
 new SAT standards

Reason: Original revisions of the SAT (SCSI-ATA Translation) specification,
 udev will identify devices starting with 70 and ending with 00 1d as ATA devices,
 rather than scsi devices, which may have a change in wwn id and affect user usage.
 So Add a new switch to control whether udev complies with the new SAT standards

---
 src/shared/udev-util.c   | 17 ++++++++++++++++-
 src/shared/udev-util.h   |  1 +
 src/udev/ata_id/ata_id.c | 18 ++++++++++++++++--
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index cf28ba8..18f03db 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -45,11 +45,17 @@ int udev_set_max_log_level(char *str) {
 }
 
 int udev_parse_config(void) {
+        return udev_parse_config_full(NULL);
+}
+
+int udev_parse_config_full(bool *ret_ignore_newer_SAT) {
         _cleanup_free_ char *log_val = NULL;
+        _cleanup_free_ char *ignore_newer_SAT = NULL;
         int r;
 
         r = parse_env_file(NULL, "/etc/udev/udev.conf",
-                           "udev_log", &log_val);
+                           "udev_log", &log_val,
+                           "ignore_newer_SAT", &ignore_newer_SAT);
         if (r == -ENOENT)
                 return 0;
         if (r < 0)
@@ -60,6 +66,15 @@ int udev_parse_config(void) {
                 log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
                            "Failed to set udev log level '%s', ignoring: %m", log_val);
 
+        if (ret_ignore_newer_SAT && ignore_newer_SAT) {
+                r = parse_boolean(ignore_newer_SAT);
+                if (r < 0)
+                        log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
+                                   "failed to parse ignore_newer_SAT=%s, ignoring.", ignore_newer_SAT);
+                else
+                    *ret_ignore_newer_SAT = r;
+        }
+
         return 0;
 }
 
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
index 651d335..ee1dbe5 100644
--- a/src/shared/udev-util.h
+++ b/src/shared/udev-util.h
@@ -8,6 +8,7 @@
 
 int udev_set_max_log_level(char *str);
 int udev_parse_config(void);
+int udev_parse_config_full(bool *ret_ignore_newer_SAT);
 
 int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t timeout_usec, sd_device **ret);
 int device_wait_for_devlink(const char *path, const char *subsystem, usec_t timeout_usec, sd_device **ret);
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c
index 0b1f0b7..92f87d9 100644
--- a/src/udev/ata_id/ata_id.c
+++ b/src/udev/ata_id/ata_id.c
@@ -31,9 +31,13 @@
 #include "memory-util.h"
 #include "udev-util.h"
 #include "unaligned.h"
+#include "proc-cmdline.h"
+#include "string-util.h"
 
 #define COMMAND_TIMEOUT_MSEC (30 * 1000)
 
+static bool arg_ignore_newer_SAT = false;
+
 static bool arg_export = false;
 static const char *arg_device = NULL;
 
@@ -159,7 +163,7 @@ static int disk_identify_command(
                         return log_debug_errno(errno, "ioctl v3 failed: %m");
         } else {
                 if (!((sense[0] & 0x7f) == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c) &&
-                    !((sense[0] & 0x7f) == 0x70 && sense[12] == 0x00 && sense[13] == 0x1d))
+                    (arg_ignore_newer_SAT || !((sense[0] & 0x7f) == 0x70 && sense[12] == 0x00 && sense[13] == 0x1d)))
                         return log_debug_errno(SYNTHETIC_ERRNO(EIO), "ioctl v4 failed: %m");
         }
 
@@ -410,10 +414,20 @@ static int run(int argc, char *argv[]) {
         int r;
 
         log_set_target(LOG_TARGET_AUTO);
-        udev_parse_config();
+        udev_parse_config_full(&arg_ignore_newer_SAT);
         log_parse_environment();
         log_open();
 
+        /* When either ignore_newer_SAT in udev.conf or udev.ignore_newer_SAT in the kernel command line is true,
+         * set arg_ignore_newer_SAT to true and ignoring the new SAT standard
+         */
+        if (!arg_ignore_newer_SAT) {
+                r = proc_cmdline_get_bool("udev.ignore_newer_SAT", /* flags = */ 0, &arg_ignore_newer_SAT);
+                if (r < 0) {
+                        log_warning_errno(r, "Failed to parse udev.ignore_newer_SAT kernel command line argument, ignoring: %m");
+                }
+        }
+
         r = parse_argv(argc, argv);
         if (r <= 0)
                 return r;
-- 
2.33.0