aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 22:01:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 22:01:29 -0400
commit242e5d06be2ad2633c85313a37862e03f4450a46 (patch)
tree9a75e5efed6ee9a4f5d9769b851ab503c1fb5ef2
parent4c5811bf463b0ef82fabbd1708f8bb2d753aeb18 (diff)
parentafe997a183ecc0be72652c7a5ce2152bdf91724e (diff)
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6: [IA64] tioca: Fix assignment from incompatible pointer warnings [IA64] mca.c: Fix cast from integer to pointer warning [IA64] setup.c Typo fix "Architechtuallly" [IA64] Add CONFIG_MISC_DEVICES=y to configs that need it. [IA64] disable interrupts at end of ia64_mca_cpe_int_handler() [IA64] Add DMA_ERROR_CODE define. pstore: fix build warning for unused return value from sysfs_create_file pstore: X86 platform interface using ACPI/APEI/ERST pstore: new filesystem interface to platform persistent storage
-rw-r--r--Documentation/ABI/testing/pstore35
-rw-r--r--Documentation/ABI/testing/sysfs-fs-pstore7
-rw-r--r--arch/ia64/configs/generic_defconfig1
-rw-r--r--arch/ia64/configs/gensparse_defconfig1
-rw-r--r--arch/ia64/include/asm/dma-mapping.h2
-rw-r--r--arch/ia64/kernel/mca.c5
-rw-r--r--arch/ia64/sn/kernel/setup.c2
-rw-r--r--arch/ia64/sn/pci/tioca_provider.c2
-rw-r--r--drivers/acpi/apei/Kconfig1
-rw-r--r--drivers/acpi/apei/erst.c136
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/Makefile1
-rw-r--r--fs/pstore/Kconfig13
-rw-r--r--fs/pstore/Makefile7
-rw-r--r--fs/pstore/inode.c285
-rw-r--r--fs/pstore/internal.h7
-rw-r--r--fs/pstore/platform.c202
-rw-r--r--include/linux/magic.h1
-rw-r--r--include/linux/pstore.h60
19 files changed, 766 insertions, 3 deletions
diff --git a/Documentation/ABI/testing/pstore b/Documentation/ABI/testing/pstore
new file mode 100644
index 000000000000..f1fb2a004264
--- /dev/null
+++ b/Documentation/ABI/testing/pstore
@@ -0,0 +1,35 @@
1Where: /dev/pstore/...
2Date: January 2011
3Kernel Version: 2.6.38
4Contact: tony.luck@intel.com
5Description: Generic interface to platform dependent persistent storage.
6
7 Platforms that provide a mechanism to preserve some data
8 across system reboots can register with this driver to
9 provide a generic interface to show records captured in
10 the dying moments. In the case of a panic the last part
11 of the console log is captured, but other interesting
12 data can also be saved.
13
14 # mount -t pstore - /dev/pstore
15
16 $ ls -l /dev/pstore
17 total 0
18 -r--r--r-- 1 root root 7896 Nov 30 15:38 dmesg-erst-1
19
20 Different users of this interface will result in different
21 filename prefixes. Currently two are defined:
22
23 "dmesg" - saved console log
24 "mce" - architecture dependent data from fatal h/w error
25
26 Once the information in a file has been read, removing
27 the file will signal to the underlying persistent storage
28 device that it can reclaim the space for later re-use.
29
30 $ rm /dev/pstore/dmesg-erst-1
31
32 The expectation is that all files in /dev/pstore
33 will be saved elsewhere and erased from persistent store
34 soon after boot to free up space ready for the next
35 catastrophe.
diff --git a/Documentation/ABI/testing/sysfs-fs-pstore b/Documentation/ABI/testing/sysfs-fs-pstore
new file mode 100644
index 000000000000..8e659d854805
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-fs-pstore
@@ -0,0 +1,7 @@
1What: /sys/fs/pstore/kmsg_bytes
2Date: January 2011
3Kernel Version: 2.6.38
4Contact: "Tony Luck" <tony.luck@intel.com>
5Description:
6 Controls amount of console log that will be saved
7 to persistent store on oops/panic.
diff --git a/arch/ia64/configs/generic_defconfig b/arch/ia64/configs/generic_defconfig
index 3ded8fe62759..1d7bca0a396d 100644
--- a/arch/ia64/configs/generic_defconfig
+++ b/arch/ia64/configs/generic_defconfig
@@ -233,3 +233,4 @@ CONFIG_CRYPTO_PCBC=m
233CONFIG_CRYPTO_MD5=y 233CONFIG_CRYPTO_MD5=y
234# CONFIG_CRYPTO_ANSI_CPRNG is not set 234# CONFIG_CRYPTO_ANSI_CPRNG is not set
235CONFIG_CRC_T10DIF=y 235CONFIG_CRC_T10DIF=y
236CONFIG_MISC_DEVICES=y
diff --git a/arch/ia64/configs/gensparse_defconfig b/arch/ia64/configs/gensparse_defconfig
index 3a98b2dd58ac..b11fa880e4b6 100644
--- a/arch/ia64/configs/gensparse_defconfig
+++ b/arch/ia64/configs/gensparse_defconfig
@@ -208,3 +208,4 @@ CONFIG_MAGIC_SYSRQ=y
208CONFIG_DEBUG_KERNEL=y 208CONFIG_DEBUG_KERNEL=y
209CONFIG_DEBUG_MUTEXES=y 209CONFIG_DEBUG_MUTEXES=y
210CONFIG_CRYPTO_MD5=y 210CONFIG_CRYPTO_MD5=y
211CONFIG_MISC_DEVICES=y
diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
index a2e7368a0150..4336d080b241 100644
--- a/arch/ia64/include/asm/dma-mapping.h
+++ b/arch/ia64/include/asm/dma-mapping.h
@@ -12,6 +12,8 @@
12 12
13#define ARCH_HAS_DMA_GET_REQUIRED_MASK 13#define ARCH_HAS_DMA_GET_REQUIRED_MASK
14 14
15#define DMA_ERROR_CODE 0
16
15extern struct dma_map_ops *dma_ops; 17extern struct dma_map_ops *dma_ops;
16extern struct ia64_machine_vector ia64_mv; 18extern struct ia64_machine_vector ia64_mv;
17extern void set_iommu_machvec(void); 19extern void set_iommu_machvec(void);
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index 1753f6a30d55..80d50b83d419 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -582,6 +582,8 @@ out:
582 /* Get the CPE error record and log it */ 582 /* Get the CPE error record and log it */
583 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE); 583 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
584 584
585 local_irq_disable();
586
585 return IRQ_HANDLED; 587 return IRQ_HANDLED;
586} 588}
587 589
@@ -1859,7 +1861,8 @@ ia64_mca_cpu_init(void *cpu_data)
1859 data = mca_bootmem(); 1861 data = mca_bootmem();
1860 first_time = 0; 1862 first_time = 0;
1861 } else 1863 } else
1862 data = __get_free_pages(GFP_KERNEL, get_order(sz)); 1864 data = (void *)__get_free_pages(GFP_KERNEL,
1865 get_order(sz));
1863 if (!data) 1866 if (!data)
1864 panic("Could not allocate MCA memory for cpu %d\n", 1867 panic("Could not allocate MCA memory for cpu %d\n",
1865 cpu); 1868 cpu);
diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index dbc4cbecb5ed..77db0b514fa4 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -592,7 +592,7 @@ void __cpuinit sn_cpu_init(void)
592 /* 592 /*
593 * Don't check status. The SAL call is not supported on all PROMs 593 * Don't check status. The SAL call is not supported on all PROMs
594 * but a failure is harmless. 594 * but a failure is harmless.
595 * Architechtuallly, cpu_init is always called twice on cpu 0. We 595 * Architecturally, cpu_init is always called twice on cpu 0. We
596 * should set cpu_number on cpu 0 once. 596 * should set cpu_number on cpu 0 once.
597 */ 597 */
598 if (cpuid == 0) { 598 if (cpuid == 0) {
diff --git a/arch/ia64/sn/pci/tioca_provider.c b/arch/ia64/sn/pci/tioca_provider.c
index 4d4536e3b6f3..9c271be9919a 100644
--- a/arch/ia64/sn/pci/tioca_provider.c
+++ b/arch/ia64/sn/pci/tioca_provider.c
@@ -509,7 +509,7 @@ tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
509 * use the GART mapped mode. 509 * use the GART mapped mode.
510 */ 510 */
511static u64 511static u64
512tioca_dma_map(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags) 512tioca_dma_map(struct pci_dev *pdev, unsigned long paddr, size_t byte_count, int dma_flags)
513{ 513{
514 u64 mapaddr; 514 u64 mapaddr;
515 515
diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig
index fca34ccfd294..e91680c7e047 100644
--- a/drivers/acpi/apei/Kconfig
+++ b/drivers/acpi/apei/Kconfig
@@ -1,5 +1,6 @@
1config ACPI_APEI 1config ACPI_APEI
2 bool "ACPI Platform Error Interface (APEI)" 2 bool "ACPI Platform Error Interface (APEI)"
3 select PSTORE
3 depends on X86 4 depends on X86
4 help 5 help
5 APEI allows to report errors (for example from the chipset) 6 APEI allows to report errors (for example from the chipset)
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index cf6db6b7662a..c02005abce43 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -34,6 +34,7 @@
34#include <linux/cper.h> 34#include <linux/cper.h>
35#include <linux/nmi.h> 35#include <linux/nmi.h>
36#include <linux/hardirq.h> 36#include <linux/hardirq.h>
37#include <linux/pstore.h>
37#include <acpi/apei.h> 38#include <acpi/apei.h>
38 39
39#include "apei-internal.h" 40#include "apei-internal.h"
@@ -781,6 +782,128 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
781 return 0; 782 return 0;
782} 783}
783 784
785static size_t erst_reader(u64 *id, enum pstore_type_id *type,
786 struct timespec *time);
787static u64 erst_writer(enum pstore_type_id type, size_t size);
788
789static struct pstore_info erst_info = {
790 .owner = THIS_MODULE,
791 .name = "erst",
792 .read = erst_reader,
793 .write = erst_writer,
794 .erase = erst_clear
795};
796
797#define CPER_CREATOR_PSTORE \
798 UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \
799 0x64, 0x90, 0xb8, 0x9d)
800#define CPER_SECTION_TYPE_DMESG \
801 UUID_LE(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \
802 0x94, 0x19, 0xeb, 0x12)
803#define CPER_SECTION_TYPE_MCE \
804 UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \
805 0x04, 0x4a, 0x38, 0xfc)
806
807struct cper_pstore_record {
808 struct cper_record_header hdr;
809 struct cper_section_descriptor sec_hdr;
810 char data[];
811} __packed;
812
813static size_t erst_reader(u64 *id, enum pstore_type_id *type,
814 struct timespec *time)
815{
816 int rc;
817 ssize_t len;
818 unsigned long flags;
819 u64 record_id;
820 struct cper_pstore_record *rcd = (struct cper_pstore_record *)
821 (erst_info.buf - sizeof(*rcd));
822
823 if (erst_disable)
824 return -ENODEV;
825
826 raw_spin_lock_irqsave(&erst_lock, flags);
827skip:
828 rc = __erst_get_next_record_id(&record_id);
829 if (rc) {
830 raw_spin_unlock_irqrestore(&erst_lock, flags);
831 return rc;
832 }
833 /* no more record */
834 if (record_id == APEI_ERST_INVALID_RECORD_ID) {
835 raw_spin_unlock_irqrestore(&erst_lock, flags);
836 return 0;
837 }
838
839 len = __erst_read(record_id, &rcd->hdr, sizeof(*rcd) +
840 erst_erange.size);
841 if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)
842 goto skip;
843 raw_spin_unlock_irqrestore(&erst_lock, flags);
844
845 *id = record_id;
846 if (uuid_le_cmp(rcd->sec_hdr.section_type,
847 CPER_SECTION_TYPE_DMESG) == 0)
848 *type = PSTORE_TYPE_DMESG;
849 else if (uuid_le_cmp(rcd->sec_hdr.section_type,
850 CPER_SECTION_TYPE_MCE) == 0)
851 *type = PSTORE_TYPE_MCE;
852 else
853 *type = PSTORE_TYPE_UNKNOWN;
854
855 if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP)
856 time->tv_sec = rcd->hdr.timestamp;
857 else
858 time->tv_sec = 0;
859 time->tv_nsec = 0;
860
861 return len - sizeof(*rcd);
862}
863
864static u64 erst_writer(enum pstore_type_id type, size_t size)
865{
866 struct cper_pstore_record *rcd = (struct cper_pstore_record *)
867 (erst_info.buf - sizeof(*rcd));
868
869 memset(rcd, 0, sizeof(*rcd));
870 memcpy(rcd->hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
871 rcd->hdr.revision = CPER_RECORD_REV;
872 rcd->hdr.signature_end = CPER_SIG_END;
873 rcd->hdr.section_count = 1;
874 rcd->hdr.error_severity = CPER_SEV_FATAL;
875 /* timestamp valid. platform_id, partition_id are invalid */
876 rcd->hdr.validation_bits = CPER_VALID_TIMESTAMP;
877 rcd->hdr.timestamp = get_seconds();
878 rcd->hdr.record_length = sizeof(*rcd) + size;
879 rcd->hdr.creator_id = CPER_CREATOR_PSTORE;
880 rcd->hdr.notification_type = CPER_NOTIFY_MCE;
881 rcd->hdr.record_id = cper_next_record_id();
882 rcd->hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR;
883
884 rcd->sec_hdr.section_offset = sizeof(*rcd);
885 rcd->sec_hdr.section_length = size;
886 rcd->sec_hdr.revision = CPER_SEC_REV;
887 /* fru_id and fru_text is invalid */
888 rcd->sec_hdr.validation_bits = 0;
889 rcd->sec_hdr.flags = CPER_SEC_PRIMARY;
890 switch (type) {
891 case PSTORE_TYPE_DMESG:
892 rcd->sec_hdr.section_type = CPER_SECTION_TYPE_DMESG;
893 break;
894 case PSTORE_TYPE_MCE:
895 rcd->sec_hdr.section_type = CPER_SECTION_TYPE_MCE;
896 break;
897 default:
898 return -EINVAL;
899 }
900 rcd->sec_hdr.section_severity = CPER_SEV_FATAL;
901
902 erst_write(&rcd->hdr);
903
904 return rcd->hdr.record_id;
905}
906
784static int __init erst_init(void) 907static int __init erst_init(void)
785{ 908{
786 int rc = 0; 909 int rc = 0;
@@ -788,6 +911,7 @@ static int __init erst_init(void)
788 struct apei_exec_context ctx; 911 struct apei_exec_context ctx;
789 struct apei_resources erst_resources; 912 struct apei_resources erst_resources;
790 struct resource *r; 913 struct resource *r;
914 char *buf;
791 915
792 if (acpi_disabled) 916 if (acpi_disabled)
793 goto err; 917 goto err;
@@ -854,6 +978,18 @@ static int __init erst_init(void)
854 if (!erst_erange.vaddr) 978 if (!erst_erange.vaddr)
855 goto err_release_erange; 979 goto err_release_erange;
856 980
981 buf = kmalloc(erst_erange.size, GFP_KERNEL);
982 mutex_init(&erst_info.buf_mutex);
983 if (buf) {
984 erst_info.buf = buf + sizeof(struct cper_pstore_record);
985 erst_info.bufsize = erst_erange.size -
986 sizeof(struct cper_pstore_record);
987 if (pstore_register(&erst_info)) {
988 pr_info(ERST_PFX "Could not register with persistent store\n");
989 kfree(buf);
990 }
991 }
992
857 pr_info(ERST_PFX 993 pr_info(ERST_PFX
858 "Error Record Serialization Table (ERST) support is initialized.\n"); 994 "Error Record Serialization Table (ERST) support is initialized.\n");
859 995
diff --git a/fs/Kconfig b/fs/Kconfig
index 7cb53aafac1e..f3aa9b08b228 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -187,6 +187,7 @@ source "fs/omfs/Kconfig"
187source "fs/hpfs/Kconfig" 187source "fs/hpfs/Kconfig"
188source "fs/qnx4/Kconfig" 188source "fs/qnx4/Kconfig"
189source "fs/romfs/Kconfig" 189source "fs/romfs/Kconfig"
190source "fs/pstore/Kconfig"
190source "fs/sysv/Kconfig" 191source "fs/sysv/Kconfig"
191source "fs/ufs/Kconfig" 192source "fs/ufs/Kconfig"
192source "fs/exofs/Kconfig" 193source "fs/exofs/Kconfig"
diff --git a/fs/Makefile b/fs/Makefile
index ba01202844c5..fb68c2b8cf8a 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -123,3 +123,4 @@ obj-$(CONFIG_BTRFS_FS) += btrfs/
123obj-$(CONFIG_GFS2_FS) += gfs2/ 123obj-$(CONFIG_GFS2_FS) += gfs2/
124obj-$(CONFIG_EXOFS_FS) += exofs/ 124obj-$(CONFIG_EXOFS_FS) += exofs/
125obj-$(CONFIG_CEPH_FS) += ceph/ 125obj-$(CONFIG_CEPH_FS) += ceph/
126obj-$(CONFIG_PSTORE) += pstore/
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
new file mode 100644
index 000000000000..867d0ac026ce
--- /dev/null
+++ b/fs/pstore/Kconfig
@@ -0,0 +1,13 @@
1config PSTORE
2 bool "Persistant store support"
3 default n
4 help
5 This option enables generic access to platform level
6 persistent storage via "pstore" filesystem that can
7 be mounted as /dev/pstore. Only useful if you have
8 a platform level driver that registers with pstore to
9 provide the data, so you probably should just go say "Y"
10 (or "M") to a platform specific persistent store driver
11 (e.g. ACPI_APEI on X86) which will select this for you.
12 If you don't have a platform persistent store driver,
13 say N.
diff --git a/fs/pstore/Makefile b/fs/pstore/Makefile
new file mode 100644
index 000000000000..760f4bce7d1d
--- /dev/null
+++ b/fs/pstore/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the linux pstorefs routines.
3#
4
5obj-y += pstore.o
6
7pstore-objs += inode.o platform.o
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
new file mode 100644
index 000000000000..549d245d0b42
--- /dev/null
+++ b/fs/pstore/inode.c
@@ -0,0 +1,285 @@
1/*
2 * Persistent Storage - ramfs parts.
3 *
4 * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/module.h>
21#include <linux/fs.h>
22#include <linux/fsnotify.h>
23#include <linux/pagemap.h>
24#include <linux/highmem.h>
25#include <linux/time.h>
26#include <linux/init.h>
27#include <linux/string.h>
28#include <linux/mount.h>
29#include <linux/ramfs.h>
30#include <linux/sched.h>
31#include <linux/magic.h>
32#include <linux/pstore.h>
33#include <linux/slab.h>
34#include <linux/uaccess.h>
35
36#include "internal.h"
37
38#define PSTORE_NAMELEN 64
39
40struct pstore_private {
41 u64 id;
42 int (*erase)(u64);
43};
44
45#define pstore_get_inode ramfs_get_inode
46
47/*
48 * When a file is unlinked from our file system we call the
49 * platform driver to erase the record from persistent store.
50 */
51static int pstore_unlink(struct inode *dir, struct dentry *dentry)
52{
53 struct pstore_private *p = dentry->d_inode->i_private;
54
55 p->erase(p->id);
56 kfree(p);
57
58 return simple_unlink(dir, dentry);
59}
60
61static const struct inode_operations pstore_dir_inode_operations = {
62 .lookup = simple_lookup,
63 .unlink = pstore_unlink,
64};
65
66static const struct super_operations pstore_ops = {
67 .statfs = simple_statfs,
68 .drop_inode = generic_delete_inode,
69 .show_options = generic_show_options,
70};
71
72static struct super_block *pstore_sb;
73static struct vfsmount *pstore_mnt;
74
75int pstore_is_mounted(void)
76{
77 return pstore_mnt != NULL;
78}
79
80/*
81 * Set up a file structure as if we had opened this file and
82 * write our data to it.
83 */
84static int pstore_writefile(struct inode *inode, struct dentry *dentry,
85 char *data, size_t size)
86{
87 struct file f;
88 ssize_t n;
89 mm_segment_t old_fs = get_fs();
90
91 memset(&f, '0', sizeof f);
92 f.f_mapping = inode->i_mapping;
93 f.f_path.dentry = dentry;
94 f.f_path.mnt = pstore_mnt;
95 f.f_pos = 0;
96 f.f_op = inode->i_fop;
97 set_fs(KERNEL_DS);
98 n = do_sync_write(&f, data, size, &f.f_pos);
99 set_fs(old_fs);
100
101 fsnotify_modify(&f);
102
103 return n == size;
104}
105
106/*
107 * Make a regular file in the root directory of our file system.
108 * Load it up with "size" bytes of data from "buf".
109 * Set the mtime & ctime to the date that this record was originally stored.
110 */
111int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
112 char *data, size_t size,
113 struct timespec time, int (*erase)(u64))
114{
115 struct dentry *root = pstore_sb->s_root;
116 struct dentry *dentry;
117 struct inode *inode;
118 int rc;
119 char name[PSTORE_NAMELEN];
120 struct pstore_private *private;
121
122 rc = -ENOMEM;
123 inode = pstore_get_inode(pstore_sb, root->d_inode, S_IFREG | 0444, 0);
124 if (!inode)
125 goto fail;
126 inode->i_uid = inode->i_gid = 0;
127 private = kmalloc(sizeof *private, GFP_KERNEL);
128 if (!private)
129 goto fail_alloc;
130 private->id = id;
131 private->erase = erase;
132
133 switch (type) {
134 case PSTORE_TYPE_DMESG:
135 sprintf(name, "dmesg-%s-%lld", psname, id);
136 break;
137 case PSTORE_TYPE_MCE:
138 sprintf(name, "mce-%s-%lld", psname, id);
139 break;
140 case PSTORE_TYPE_UNKNOWN:
141 sprintf(name, "unknown-%s-%lld", psname, id);
142 break;
143 default:
144 sprintf(name, "type%d-%s-%lld", type, psname, id);
145 break;
146 }
147
148 mutex_lock(&root->d_inode->i_mutex);
149
150 rc = -ENOSPC;
151 dentry = d_alloc_name(root, name);
152 if (IS_ERR(dentry))
153 goto fail_lockedalloc;
154
155 d_add(dentry, inode);
156
157 mutex_unlock(&root->d_inode->i_mutex);
158
159 if (!pstore_writefile(inode, dentry, data, size))
160 goto fail_write;
161
162 inode->i_private = private;
163
164 if (time.tv_sec)
165 inode->i_mtime = inode->i_ctime = time;
166
167 return 0;
168
169fail_write:
170 kfree(private);
171 inode->i_nlink--;
172 mutex_lock(&root->d_inode->i_mutex);
173 d_delete(dentry);
174 dput(dentry);
175 mutex_unlock(&root->d_inode->i_mutex);
176 goto fail;
177
178fail_lockedalloc:
179 mutex_unlock(&root->d_inode->i_mutex);
180 kfree(private);
181fail_alloc:
182 iput(inode);
183
184fail:
185 return rc;
186}
187
188int pstore_fill_super(struct super_block *sb, void *data, int silent)
189{
190 struct inode *inode = NULL;
191 struct dentry *root;
192 int err;
193
194 save_mount_options(sb, data);
195
196 pstore_sb = sb;
197
198 sb->s_maxbytes = MAX_LFS_FILESIZE;
199 sb->s_blocksize = PAGE_CACHE_SIZE;
200 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
201 sb->s_magic = PSTOREFS_MAGIC;
202 sb->s_op = &pstore_ops;
203 sb->s_time_gran = 1;
204
205 inode = pstore_get_inode(sb, NULL, S_IFDIR | 0755, 0);
206 if (!inode) {
207 err = -ENOMEM;
208 goto fail;
209 }
210 /* override ramfs "dir" options so we catch unlink(2) */
211 inode->i_op = &pstore_dir_inode_operations;
212
213 root = d_alloc_root(inode);
214 sb->s_root = root;
215 if (!root) {
216 err = -ENOMEM;
217 goto fail;
218 }
219
220 pstore_get_records();
221
222 return 0;
223fail:
224 iput(inode);
225 return err;
226}
227
228static int pstore_get_sb(struct file_system_type *fs_type,
229 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
230{
231 struct dentry *root;
232
233 root = mount_nodev(fs_type, flags, data, pstore_fill_super);
234 if (IS_ERR(root))
235 return -ENOMEM;
236
237 mnt->mnt_root = root;
238 mnt->mnt_sb = root->d_sb;
239 pstore_mnt = mnt;
240
241 return 0;
242}
243
244static void pstore_kill_sb(struct super_block *sb)
245{
246 kill_litter_super(sb);
247 pstore_sb = NULL;
248 pstore_mnt = NULL;
249}
250
251static struct file_system_type pstore_fs_type = {
252 .name = "pstore",
253 .get_sb = pstore_get_sb,
254 .kill_sb = pstore_kill_sb,
255};
256
257static int __init init_pstore_fs(void)
258{
259 int rc = 0;
260 struct kobject *pstorefs_kobj;
261
262 pstorefs_kobj = kobject_create_and_add("pstore", fs_kobj);
263 if (!pstorefs_kobj) {
264 rc = -ENOMEM;
265 goto done;
266 }
267
268 rc = sysfs_create_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr);
269 if (rc)
270 goto done1;
271
272 rc = register_filesystem(&pstore_fs_type);
273 if (rc == 0)
274 goto done;
275
276 sysfs_remove_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr);
277done1:
278 kobject_put(pstorefs_kobj);
279done:
280 return rc;
281}
282module_init(init_pstore_fs)
283
284MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
285MODULE_LICENSE("GPL");
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h
new file mode 100644
index 000000000000..76c26d2fab29
--- /dev/null
+++ b/fs/pstore/internal.h
@@ -0,0 +1,7 @@
1extern void pstore_get_records(void);
2extern int pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
3 char *data, size_t size,
4 struct timespec time, int (*erase)(u64));
5extern int pstore_is_mounted(void);
6
7extern struct kobj_attribute pstore_kmsg_bytes_attr;
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
new file mode 100644
index 000000000000..705fdf8abf6e
--- /dev/null
+++ b/fs/pstore/platform.c
@@ -0,0 +1,202 @@
1/*
2 * Persistent Storage - platform driver interface parts.
3 *
4 * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/atomic.h>
21#include <linux/types.h>
22#include <linux/errno.h>
23#include <linux/init.h>
24#include <linux/kmsg_dump.h>
25#include <linux/module.h>
26#include <linux/pstore.h>
27#include <linux/string.h>
28#include <linux/slab.h>
29#include <linux/uaccess.h>
30
31#include "internal.h"
32
33/*
34 * pstore_lock just protects "psinfo" during
35 * calls to pstore_register()
36 */
37static DEFINE_SPINLOCK(pstore_lock);
38static struct pstore_info *psinfo;
39
40/* How much of the console log to snapshot. /sys/fs/pstore/kmsg_bytes */
41static unsigned long kmsg_bytes = 10240;
42
43static ssize_t b_show(struct kobject *kobj,
44 struct kobj_attribute *attr, char *buf)
45{
46 return snprintf(buf, PAGE_SIZE, "%lu\n", kmsg_bytes);
47}
48
49static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
50 const char *buf, size_t count)
51{
52 return (sscanf(buf, "%lu", &kmsg_bytes) > 0) ? count : 0;
53}
54
55struct kobj_attribute pstore_kmsg_bytes_attr =
56 __ATTR(kmsg_bytes, S_IRUGO | S_IWUSR, b_show, b_store);
57
58/* Tag each group of saved records with a sequence number */
59static int oopscount;
60
61/*
62 * callback from kmsg_dump. (s2,l2) has the most recently
63 * written bytes, older bytes are in (s1,l1). Save as much
64 * as we can from the end of the buffer.
65 */
66static void pstore_dump(struct kmsg_dumper *dumper,
67 enum kmsg_dump_reason reason,
68 const char *s1, unsigned long l1,
69 const char *s2, unsigned long l2)
70{
71 unsigned long s1_start, s2_start;
72 unsigned long l1_cpy, l2_cpy;
73 unsigned long size, total = 0;
74 char *dst;
75 u64 id;
76 int hsize, part = 1;
77
78 mutex_lock(&psinfo->buf_mutex);
79 oopscount++;
80 while (total < kmsg_bytes) {
81 dst = psinfo->buf;
82 hsize = sprintf(dst, "Oops#%d Part%d\n", oopscount, part++);
83 size = psinfo->bufsize - hsize;
84 dst += hsize;
85
86 l2_cpy = min(l2, size);
87 l1_cpy = min(l1, size - l2_cpy);
88
89 if (l1_cpy + l2_cpy == 0)
90 break;
91
92 s2_start = l2 - l2_cpy;
93 s1_start = l1 - l1_cpy;
94
95 memcpy(dst, s1 + s1_start, l1_cpy);
96 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
97
98 id = psinfo->write(PSTORE_TYPE_DMESG, hsize + l1_cpy + l2_cpy);
99 if (pstore_is_mounted())
100 pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id,
101 psinfo->buf, hsize + l1_cpy + l2_cpy,
102 CURRENT_TIME, psinfo->erase);
103 l1 -= l1_cpy;
104 l2 -= l2_cpy;
105 total += l1_cpy + l2_cpy;
106 }
107 mutex_unlock(&psinfo->buf_mutex);
108}
109
110static struct kmsg_dumper pstore_dumper = {
111 .dump = pstore_dump,
112};
113
114/*
115 * platform specific persistent storage driver registers with
116 * us here. If pstore is already mounted, call the platform
117 * read function right away to populate the file system. If not
118 * then the pstore mount code will call us later to fill out
119 * the file system.
120 *
121 * Register with kmsg_dump to save last part of console log on panic.
122 */
123int pstore_register(struct pstore_info *psi)
124{
125 struct module *owner = psi->owner;
126
127 spin_lock(&pstore_lock);
128 if (psinfo) {
129 spin_unlock(&pstore_lock);
130 return -EBUSY;
131 }
132 psinfo = psi;
133 spin_unlock(&pstore_lock);
134
135 if (owner && !try_module_get(owner)) {
136 psinfo = NULL;
137 return -EINVAL;
138 }
139
140 if (pstore_is_mounted())
141 pstore_get_records();
142
143 kmsg_dump_register(&pstore_dumper);
144
145 return 0;
146}
147EXPORT_SYMBOL_GPL(pstore_register);
148
149/*
150 * Read all the records from the persistent store. Create and
151 * file files in our filesystem.
152 */
153void pstore_get_records(void)
154{
155 struct pstore_info *psi = psinfo;
156 size_t size;
157 u64 id;
158 enum pstore_type_id type;
159 struct timespec time;
160 int failed = 0;
161
162 if (!psi)
163 return;
164
165 mutex_lock(&psinfo->buf_mutex);
166 while ((size = psi->read(&id, &type, &time)) > 0) {
167 if (pstore_mkfile(type, psi->name, id, psi->buf, size,
168 time, psi->erase))
169 failed++;
170 }
171 mutex_unlock(&psinfo->buf_mutex);
172
173 if (failed)
174 printk(KERN_WARNING "pstore: failed to load %d record(s) from '%s'\n",
175 failed, psi->name);
176}
177
178/*
179 * Call platform driver to write a record to the
180 * persistent store.
181 */
182int pstore_write(enum pstore_type_id type, char *buf, size_t size)
183{
184 u64 id;
185
186 if (!psinfo)
187 return -ENODEV;
188
189 if (size > psinfo->bufsize)
190 return -EFBIG;
191
192 mutex_lock(&psinfo->buf_mutex);
193 memcpy(psinfo->buf, buf, size);
194 id = psinfo->write(type, size);
195 if (pstore_is_mounted())
196 pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, psinfo->buf,
197 size, CURRENT_TIME, psinfo->erase);
198 mutex_unlock(&psinfo->buf_mutex);
199
200 return 0;
201}
202EXPORT_SYMBOL_GPL(pstore_write);
diff --git a/include/linux/magic.h b/include/linux/magic.h
index 62730ea2b56e..6cfe344f9559 100644
--- a/include/linux/magic.h
+++ b/include/linux/magic.h
@@ -27,6 +27,7 @@
27#define ISOFS_SUPER_MAGIC 0x9660 27#define ISOFS_SUPER_MAGIC 0x9660
28#define JFFS2_SUPER_MAGIC 0x72b6 28#define JFFS2_SUPER_MAGIC 0x72b6
29#define ANON_INODE_FS_MAGIC 0x09041934 29#define ANON_INODE_FS_MAGIC 0x09041934
30#define PSTOREFS_MAGIC 0x6165676C
30 31
31#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ 32#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
32#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ 33#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
new file mode 100644
index 000000000000..41977737bb7d
--- /dev/null
+++ b/include/linux/pstore.h
@@ -0,0 +1,60 @@
1/*
2 * Persistent Storage - pstore.h
3 *
4 * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
5 *
6 * This code is the generic layer to export data records from platform
7 * level persistent storage via a file system.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#ifndef _LINUX_PSTORE_H
23#define _LINUX_PSTORE_H
24
25/* types */
26enum pstore_type_id {
27 PSTORE_TYPE_DMESG = 0,
28 PSTORE_TYPE_MCE = 1,
29 PSTORE_TYPE_UNKNOWN = 255
30};
31
32struct pstore_info {
33 struct module *owner;
34 char *name;
35 struct mutex buf_mutex; /* serialize access to 'buf' */
36 char *buf;
37 size_t bufsize;
38 size_t (*read)(u64 *id, enum pstore_type_id *type,
39 struct timespec *time);
40 u64 (*write)(enum pstore_type_id type, size_t size);
41 int (*erase)(u64 id);
42};
43
44#ifdef CONFIG_PSTORE
45extern int pstore_register(struct pstore_info *);
46extern int pstore_write(enum pstore_type_id type, char *buf, size_t size);
47#else
48static inline int
49pstore_register(struct pstore_info *psi)
50{
51 return -ENODEV;
52}
53static inline int
54pstore_write(enum pstore_type_id type, char *buf, size_t size)
55{
56 return -ENODEV;
57}
58#endif
59
60#endif /*_LINUX_PSTORE_H*/