Skip to content

Commit 3f8f80f

Browse files
arunabalaegl
authored andcommitted
pstore/ram: Read and write to the 'compressed' flag of pstore
In pstore write, add character 'C'(compressed) or 'D'(decompressed) in the header while writing to Ram persistent buffer. In pstore read, read the header and update the 'compressed' flag accordingly. Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent f8c62f3 commit 3f8f80f

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎fs/pstore/ram.c‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
131131
return prz;
132132
}
133133

134+
static void ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
135+
bool *compressed)
136+
{
137+
char data_type;
138+
139+
if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
140+
&time->tv_sec, &time->tv_nsec, &data_type) == 3) {
141+
if (data_type == 'C')
142+
*compressed = true;
143+
else
144+
*compressed = false;
145+
} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
146+
&time->tv_sec, &time->tv_nsec) == 2) {
147+
*compressed = false;
148+
} else {
149+
time->tv_sec = 0;
150+
time->tv_nsec = 0;
151+
*compressed = false;
152+
}
153+
}
154+
134155
static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
135156
int *count, struct timespec *time,
136157
char **buf, bool *compressed,
@@ -153,10 +174,6 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
153174
if (!prz)
154175
return 0;
155176

156-
/* TODO(kees): Bogus time for the moment. */
157-
time->tv_sec = 0;
158-
time->tv_nsec = 0;
159-
160177
size = persistent_ram_old_size(prz);
161178

162179
/* ECC correction notice */
@@ -167,12 +184,14 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
167184
return -ENOMEM;
168185

169186
memcpy(*buf, persistent_ram_old(prz), size);
187+
ramoops_read_kmsg_hdr(*buf, time, compressed);
170188
persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1);
171189

172190
return size + ecc_notice_size;
173191
}
174192

175-
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
193+
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
194+
bool compressed)
176195
{
177196
char *hdr;
178197
struct timespec timestamp;
@@ -183,8 +202,9 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
183202
timestamp.tv_sec = 0;
184203
timestamp.tv_nsec = 0;
185204
}
186-
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
187-
(long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000));
205+
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
206+
(long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000),
207+
compressed ? 'C' : 'D');
188208
WARN_ON_ONCE(!hdr);
189209
len = hdr ? strlen(hdr) : 0;
190210
persistent_ram_write(prz, hdr, len);
@@ -243,7 +263,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
243263

244264
prz = cxt->przs[cxt->dump_write_cnt];
245265

246-
hlen = ramoops_write_kmsg_hdr(prz);
266+
hlen = ramoops_write_kmsg_hdr(prz, compressed);
247267
if (size + hlen > prz->buffer_size)
248268
size = prz->buffer_size - hlen;
249269
persistent_ram_write(prz, buf, size);

0 commit comments

Comments
 (0)