Skip to content

Commit 06cf91b

Browse files
Chen Gongaegl
authored andcommitted
pstore: fix pstore filesystem mount/remount issue
Currently after mount/remount operation on pstore filesystem, the content on pstore will be lost. It is because current ERST implementation doesn't support multi-user usage, which moves internal pointer to the end after accessing it. Adding multi-user support for pstore usage. Signed-off-by: Chen Gong <gong.chen@linux.intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent 8d38d74 commit 06cf91b

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

‎drivers/acpi/apei/erst.c‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -929,13 +929,17 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
929929
return 0;
930930
}
931931

932+
static int erst_open_pstore(struct pstore_info *psi);
933+
static int erst_close_pstore(struct pstore_info *psi);
932934
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
933935
struct timespec *time);
934936
static u64 erst_writer(enum pstore_type_id type, size_t size);
935937

936938
static struct pstore_info erst_info = {
937939
.owner = THIS_MODULE,
938940
.name = "erst",
941+
.open = erst_open_pstore,
942+
.close = erst_close_pstore,
939943
.read = erst_reader,
940944
.write = erst_writer,
941945
.erase = erst_clear
@@ -957,37 +961,54 @@ struct cper_pstore_record {
957961
char data[];
958962
} __packed;
959963

964+
static int reader_pos;
965+
966+
static int erst_open_pstore(struct pstore_info *psi)
967+
{
968+
int rc;
969+
970+
if (erst_disable)
971+
return -ENODEV;
972+
973+
rc = erst_get_record_id_begin(&reader_pos);
974+
975+
return rc;
976+
}
977+
978+
static int erst_close_pstore(struct pstore_info *psi)
979+
{
980+
erst_get_record_id_end();
981+
982+
return 0;
983+
}
984+
960985
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
961986
struct timespec *time)
962987
{
963988
int rc;
964-
ssize_t len;
965-
unsigned long flags;
989+
ssize_t len = 0;
966990
u64 record_id;
967991
struct cper_pstore_record *rcd = (struct cper_pstore_record *)
968992
(erst_info.buf - sizeof(*rcd));
969993

970994
if (erst_disable)
971995
return -ENODEV;
972996

973-
raw_spin_lock_irqsave(&erst_lock, flags);
974997
skip:
975-
rc = __erst_get_next_record_id(&record_id);
976-
if (rc) {
977-
raw_spin_unlock_irqrestore(&erst_lock, flags);
978-
return rc;
979-
}
998+
rc = erst_get_record_id_next(&reader_pos, &record_id);
999+
if (rc)
1000+
goto out;
1001+
9801002
/* no more record */
9811003
if (record_id == APEI_ERST_INVALID_RECORD_ID) {
982-
raw_spin_unlock_irqrestore(&erst_lock, flags);
983-
return 0;
1004+
rc = -1;
1005+
goto out;
9841006
}
9851007

986-
len = __erst_read(record_id, &rcd->hdr, sizeof(*rcd) +
1008+
len = erst_read(record_id, &rcd->hdr, sizeof(*rcd) +
9871009
erst_erange.size);
9881010
if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)
9891011
goto skip;
990-
raw_spin_unlock_irqrestore(&erst_lock, flags);
9911012

9921013
*id = record_id;
9931014
if (uuid_le_cmp(rcd->sec_hdr.section_type,
@@ -1005,7 +1026,8 @@ static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
10051026
time->tv_sec = 0;
10061027
time->tv_nsec = 0;
10071028

1008-
return len - sizeof(*rcd);
1029+
out:
1030+
return (rc < 0) ? rc : (len - sizeof(*rcd));
10091031
}
10101032

10111033
static u64 erst_writer(enum pstore_type_id type, size_t size)

‎fs/pstore/platform.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,23 @@ void pstore_get_records(void)
156156
u64 id;
157157
enum pstore_type_id type;
158158
struct timespec time;
159-
int failed = 0;
159+
int failed = 0, rc;
160160

161161
if (!psi)
162162
return;
163163

164164
mutex_lock(&psinfo->buf_mutex);
165+
rc = psi->open(psi);
166+
if (rc)
167+
goto out;
168+
165169
while ((size = psi->read(&id, &type, &time)) > 0) {
166170
if (pstore_mkfile(type, psi->name, id, psi->buf, (size_t)size,
167171
time, psi->erase))
168172
failed++;
169173
}
174+
psi->close(psi);
175+
out:
170176
mutex_unlock(&psinfo->buf_mutex);
171177

172178
if (failed)

‎include/linux/pstore.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct pstore_info {
3535
struct mutex buf_mutex; /* serialize access to 'buf' */
3636
char *buf;
3737
size_t bufsize;
38+
int (*open)(struct pstore_info *psi);
39+
int (*close)(struct pstore_info *psi);
3840
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
3941
struct timespec *time);
4042
u64 (*write)(enum pstore_type_id type, size_t size);

0 commit comments

Comments
 (0)