@@ -74,16 +74,43 @@ int storage_init(const char *storage_root, bool read_only, bool use_partitions)
74
74
return 0 ;
75
75
}
76
76
77
- struct rmtfd * storage_open (unsigned node , const char * path )
77
+ static int fd_open (struct rmtfd * rmtfd , const char * fspath , const struct partition * part )
78
+ {
79
+ int saved_errno ;
80
+ int ret ;
81
+ int fd ;
82
+
83
+ if (!storage_read_only ) {
84
+ fd = open (fspath , O_RDWR );
85
+ if (fd < 0 ) {
86
+ saved_errno = errno ;
87
+ fprintf (stderr , "[storage] failed to open '%s' (requested '%s'): %s\n" ,
88
+ fspath , part -> path , strerror (saved_errno ));
89
+ return saved_errno ;
90
+ }
91
+ rmtfd -> fd = fd ;
92
+ rmtfd -> shadow_len = 0 ;
93
+ } else {
94
+ ret = storage_populate_shadow_buf (rmtfd , fspath );
95
+ if (ret < 0 ) {
96
+ saved_errno = errno ;
97
+ fprintf (stderr , "[storage] failed to open '%s' (requested '%s'): %s\n" ,
98
+ fspath , part -> path , strerror (saved_errno ));
99
+ return saved_errno ;
100
+ }
101
+ }
102
+
103
+ return 0 ;
104
+ }
105
+
106
+ struct rmtfd * storage_open (unsigned node , const char * path , const char * slot_suffix )
78
107
{
79
108
char * fspath ;
80
109
const struct partition * part ;
81
110
struct rmtfd * rmtfd = NULL ;
82
111
const char * file ;
83
112
size_t pathlen ;
84
- int saved_errno ;
85
113
int ret ;
86
- int fd ;
87
114
int i ;
88
115
89
116
for (part = partition_table ; part -> path ; part ++ ) {
@@ -119,29 +146,19 @@ struct rmtfd *storage_open(unsigned node, const char *path)
119
146
else
120
147
file = part -> actual ;
121
148
122
- pathlen = strlen (storage_dir ) + strlen (file ) + 2 ;
149
+ pathlen = strlen (storage_dir ) + strlen (file ) + 2 + strnlen ( slot_suffix , SLOT_SUFFIX_LEN ) ;
123
150
fspath = alloca (pathlen );
124
151
snprintf (fspath , pathlen , "%s/%s" , storage_dir , file );
125
- if (!storage_read_only ) {
126
- fd = open (fspath , O_RDWR );
127
- if (fd < 0 ) {
128
- saved_errno = errno ;
129
- fprintf (stderr , "[storage] failed to open '%s' (requested '%s'): %s\n" ,
130
- fspath , part -> path , strerror (saved_errno ));
131
- errno = saved_errno ;
152
+ ret = fd_open (rmtfd , fspath , part );
153
+ if (ret ) {
154
+ /* Try again with the slot suffix before giving up */
155
+ if (!slot_suffix )
132
156
return NULL ;
133
- }
134
- rmtfd -> fd = fd ;
135
- rmtfd -> shadow_len = 0 ;
136
- } else {
137
- ret = storage_populate_shadow_buf (rmtfd , fspath );
138
- if (ret < 0 ) {
139
- saved_errno = errno ;
140
- fprintf (stderr , "[storage] failed to open '%s' (requested '%s'): %s\n" ,
141
- fspath , part -> path , strerror (saved_errno ));
142
- errno = saved_errno ;
157
+
158
+ snprintf (fspath , pathlen , "%s/%s%s" , storage_dir , file , slot_suffix );
159
+ ret = fd_open (rmtfd , fspath , part );
160
+ if (ret )
143
161
return NULL ;
144
- }
145
162
}
146
163
147
164
rmtfd -> node = node ;
0 commit comments