diff mbox

[OPW,kernel,v3,3/4] fs: pstore: Add timespec to timespec64 conversion

Message ID 1415123521-4564-4-git-send-email-somyaanand214@gmail.com
State New, archived
Headers show

Commit Message

Somya Anand Nov. 4, 2014, 5:52 p.m. UTC
32-bit systems using 'struct timespec' will break in the year 2038,
so we have to replace that code with more appropriate types.

Introducing a local variable of type 'struct timespec64' to update
interface of pstore_info.read and pstore_info.erase in order to support
new pstore_info API.

pstore_mkfile(..) is modified to use 'struct timespec64' instead of
'struct timespec'.

__getnstimeofday64() is used instead of __getnstimeofday() as it uses
'struct timespec64'.

Signed-off-by: Somya Anand <somyaanand214@gmail.com>
---
Changes since version 2:
  * Use timespec64_to_timespec conversion.
  * Use __getnstimeofday64() instead of getnstimeofday64().
  * Reword commit message.
 fs/pstore/inode.c    |  2 +-
 fs/pstore/internal.h |  2 +-
 fs/pstore/platform.c |  5 ++++-
 fs/pstore/ram.c      | 17 ++++++++++-------
 4 files changed, 16 insertions(+), 10 deletions(-)

Comments

Arnd Bergmann Nov. 4, 2014, 9:42 p.m. UTC | #1
On Tuesday 04 November 2014 23:22:00 Somya Anand wrote:
> diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
> index fafb7a0..ce1a093 100644
> --- a/fs/pstore/inode.c
> +++ b/fs/pstore/inode.c
> @@ -277,7 +277,7 @@ int pstore_is_mounted(void)
>   */
>  int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
>  		  char *data, bool compressed, size_t size,
> -		  struct timespec time, struct pstore_info *psi)
> +		  struct timespec64 time, struct pstore_info *psi)
>  {
>  	struct dentry		*root = pstore_sb->s_root;
>  	struct dentry		*dentry;

The changes to the pstore file system don't seem to belong into
the same patch as the ramoops changes. I would just leave them
until the end.

> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 3b57443..550bb0b 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -135,18 +135,18 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
>  	return prz;
>  }
>  
> -static void ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
> +static void ramoops_read_kmsg_hdr(char *buffer, struct timespec64 *time,
>  				  bool *compressed)
>  {
>  	char data_type;
>  
> -	if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
> +	if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%ld.%ld-%c\n",
>  			&time->tv_sec, &time->tv_nsec, &data_type) == 3) {
>  		if (data_type == 'C')
>  			*compressed = true;
>  		else
>  			*compressed = false;
> -	} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
> +	} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%ld.%ld\n",
>  			&time->tv_sec, &time->tv_nsec) == 2) {
>  			*compressed = false;
>  	} else {

Same bug as patch 2

> @@ -189,6 +191,8 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
>  
>  	memcpy(*buf, persistent_ram_old(prz), size);
>  	ramoops_read_kmsg_hdr(*buf, time, compressed);
> +	ts_temp = timespec64_to_timespec(*time);
> +	ts = &ts_temp;
>  	persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1);
>  
>  	return size + ecc_notice_size;

Same bug as all other patches.

	Arnd
diff mbox

Patch

diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index fafb7a0..ce1a093 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -277,7 +277,7 @@  int pstore_is_mounted(void)
  */
 int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
 		  char *data, bool compressed, size_t size,
-		  struct timespec time, struct pstore_info *psi)
+		  struct timespec64 time, struct pstore_info *psi)
 {
 	struct dentry		*root = pstore_sb->s_root;
 	struct dentry		*dentry;
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h
index 3b3d305..29778d1 100644
--- a/fs/pstore/internal.h
+++ b/fs/pstore/internal.h
@@ -51,7 +51,7 @@  extern void	pstore_set_kmsg_bytes(int);
 extern void	pstore_get_records(int);
 extern int	pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
 			      int count, char *data, bool compressed,
-			      size_t size, struct timespec time,
+			      size_t size, struct timespec64 time,
 			      struct pstore_info *psi);
 extern int	pstore_is_mounted(void);
 
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 0a9b72c..2070e93 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -479,6 +479,7 @@  void pstore_get_records(int quiet)
 	int			failed = 0, rc;
 	bool			compressed;
 	int			unzipped_len = -1;
+	struct timespec64	ts64_temp;
 
 	if (!psi)
 		return;
@@ -489,6 +490,7 @@  void pstore_get_records(int quiet)
 
 	while ((size = psi->read(&id, &type, &count, &time, &buf, &compressed,
 				psi)) > 0) {
+		ts64_temp = timespec_to_timespec64(time);
 		if (compressed && (type == PSTORE_TYPE_DMESG)) {
 			if (big_oops_buf)
 				unzipped_len = pstore_decompress(buf,
@@ -507,7 +509,8 @@  void pstore_get_records(int quiet)
 			}
 		}
 		rc = pstore_mkfile(type, psi->name, id, count, buf,
-				  compressed, (size_t)size, time, psi);
+				  compressed, (size_t)size,
+				  ts64_temp, psi);
 		if (unzipped_len < 0) {
 			/* Free buffer other than big oops */
 			kfree(buf);
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 3b57443..550bb0b 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -135,18 +135,18 @@  ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
 	return prz;
 }
 
-static void ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
+static void ramoops_read_kmsg_hdr(char *buffer, struct timespec64 *time,
 				  bool *compressed)
 {
 	char data_type;
 
-	if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
+	if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%ld.%ld-%c\n",
 			&time->tv_sec, &time->tv_nsec, &data_type) == 3) {
 		if (data_type == 'C')
 			*compressed = true;
 		else
 			*compressed = false;
-	} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
+	} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%ld.%ld\n",
 			&time->tv_sec, &time->tv_nsec) == 2) {
 			*compressed = false;
 	} else {
@@ -157,10 +157,12 @@  static void ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
 }
 
 static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
-				   int *count, struct timespec *time,
+				   int *count, struct timespec *ts,
 				   char **buf, bool *compressed,
 				   struct pstore_info *psi)
 {
+	struct timespec ts_temp;
+	struct timespec64 *time;
 	ssize_t size;
 	ssize_t ecc_notice_size;
 	struct ramoops_context *cxt = psi->data;
@@ -189,6 +191,8 @@  static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
 
 	memcpy(*buf, persistent_ram_old(prz), size);
 	ramoops_read_kmsg_hdr(*buf, time, compressed);
+	ts_temp = timespec64_to_timespec(*time);
+	ts = &ts_temp;
 	persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1);
 
 	return size + ecc_notice_size;
@@ -198,11 +202,10 @@  static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
 				     bool compressed)
 {
 	char *hdr;
-	struct timespec timestamp;
+	struct timespec64 timestamp;
 	size_t len;
-
 	/* Report zeroed timestamp if called before timekeeping has resumed. */
-	if (__getnstimeofday(&timestamp)) {
+	if (__getnstimeofday64(&timestamp)) {
 		timestamp.tv_sec = 0;
 		timestamp.tv_nsec = 0;
 	}