diff options
author | Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> | 2013-08-16 16:58:00 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2013-08-19 14:53:50 -0400 |
commit | 3f8f80f0cfebab185b6fe599c53b63e7e8ae02c9 (patch) | |
tree | 4176db7f1cb1868b6ceb589061df2112f23c0e1f | |
parent | f8c62f34fe868f5bcca88a32e4a5c52b67de661d (diff) |
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>
-rw-r--r-- | fs/pstore/ram.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 292722327811..4027c2065842 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c | |||
@@ -131,6 +131,27 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, | |||
131 | return prz; | 131 | return prz; |
132 | } | 132 | } |
133 | 133 | ||
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 | |||
134 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | 155 | static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, |
135 | int *count, struct timespec *time, | 156 | int *count, struct timespec *time, |
136 | char **buf, bool *compressed, | 157 | char **buf, bool *compressed, |
@@ -153,10 +174,6 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | |||
153 | if (!prz) | 174 | if (!prz) |
154 | return 0; | 175 | return 0; |
155 | 176 | ||
156 | /* TODO(kees): Bogus time for the moment. */ | ||
157 | time->tv_sec = 0; | ||
158 | time->tv_nsec = 0; | ||
159 | |||
160 | size = persistent_ram_old_size(prz); | 177 | size = persistent_ram_old_size(prz); |
161 | 178 | ||
162 | /* ECC correction notice */ | 179 | /* ECC correction notice */ |
@@ -167,12 +184,14 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | |||
167 | return -ENOMEM; | 184 | return -ENOMEM; |
168 | 185 | ||
169 | memcpy(*buf, persistent_ram_old(prz), size); | 186 | memcpy(*buf, persistent_ram_old(prz), size); |
187 | ramoops_read_kmsg_hdr(*buf, time, compressed); | ||
170 | persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1); | 188 | persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1); |
171 | 189 | ||
172 | return size + ecc_notice_size; | 190 | return size + ecc_notice_size; |
173 | } | 191 | } |
174 | 192 | ||
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) | ||
176 | { | 195 | { |
177 | char *hdr; | 196 | char *hdr; |
178 | struct timespec timestamp; | 197 | struct timespec timestamp; |
@@ -183,8 +202,9 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz) | |||
183 | timestamp.tv_sec = 0; | 202 | timestamp.tv_sec = 0; |
184 | timestamp.tv_nsec = 0; | 203 | timestamp.tv_nsec = 0; |
185 | } | 204 | } |
186 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n", | 205 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n", |
187 | (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000)); | 206 | (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000), |
207 | compressed ? 'C' : 'D'); | ||
188 | WARN_ON_ONCE(!hdr); | 208 | WARN_ON_ONCE(!hdr); |
189 | len = hdr ? strlen(hdr) : 0; | 209 | len = hdr ? strlen(hdr) : 0; |
190 | persistent_ram_write(prz, hdr, len); | 210 | persistent_ram_write(prz, hdr, len); |
@@ -243,7 +263,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type, | |||
243 | 263 | ||
244 | prz = cxt->przs[cxt->dump_write_cnt]; | 264 | prz = cxt->przs[cxt->dump_write_cnt]; |
245 | 265 | ||
246 | hlen = ramoops_write_kmsg_hdr(prz); | 266 | hlen = ramoops_write_kmsg_hdr(prz, compressed); |
247 | if (size + hlen > prz->buffer_size) | 267 | if (size + hlen > prz->buffer_size) |
248 | size = prz->buffer_size - hlen; | 268 | size = prz->buffer_size - hlen; |
249 | persistent_ram_write(prz, buf, size); | 269 | persistent_ram_write(prz, buf, size); |