Skip to contentSkip to conversation

recover from iclog allocation failures

PATCH In review Eric Sandeen 3 participants 4 messages Feb 9, 2008 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 recover from iclog allocation failures

A user in #xfs had some strange thing hogging up vmalloc space, and after mounting several xfs filesystems with aggressive log memory usage, started hitting vmalloc failures which led to an oops.

I inserted a fake failure at i=3 in the iclog alloc loop, and this patch let me exit with a graceful "ENOMEM" instead of an oops.

Also, somehow the use of "uuid_mounted" has gone stale; after the graceful mount failure, I got dup uuid errors on the next mount. This patch fixes that problem as well.

---

fs/xfs/xfs_log.c +9 -0
Index: linux-2.6.24.noarch/fs/xfs/xfs_log.c
===================================================================
@@ -513,6 +513,8 @@ xfs_log_mount(xfs_mount_t	*mp,
 	}
 
 	mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
+	if (!mp->m_log)
+		return ENOMEM;
 
 	/*
 	 * skip log recovery on a norecovery mount.  pretend it all
@@ -1219,6 +1221,13 @@ xlog_alloc_log(xfs_mount_t	*mp,
 		prev_iclog = iclog;
 
 		bp = xfs_buf_get_noaddr(log->l_iclog_size, mp->m_logdev_targp);
+		if (!iclog || !bp) {
+			if (iclog)
+				kmem_free(iclog, sizeof(xlog_in_core_t));
+			log->l_iclog_bufs = i;
+			xlog_dealloc_log(log);
+			return NULL;
+		}
 		if (!XFS_BUF_CPSEMA(bp))
 			ASSERT(0);
 		XFS_BUF_SET_IODONE_FUNC(bp, xlog_iodone);
fs/xfs/xfs_mount.c +1 -0
Index: linux-2.6.24.noarch/fs/xfs/xfs_mount.c
===================================================================
@@ -1007,6 +1007,7 @@ xfs_mountfs(
 			error = XFS_ERROR(EINVAL);
 			goto error1;
 		}
+		uuid_mounted = 1;
 	}
 
 	/*
#1 lore raw

fs/xfs/xfs_log.c xfs_log_mount(xfs_mount_t *mp, · line 517

Quoted 3 lines · Eric Sandeen
fs/xfs/xfs_log.c +2 -0
 	mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
+	if (!mp->m_log)
+		return ENOMEM;

Currently there's no allocations in there that should be able to fail. But actually marking these KM_MAYFAIL would be a good idea.

fs/xfs/xfs_log.c xlog_alloc_log(xfs_mount_t *mp, · line 1230

Quoted 11 lines
fs/xfs/xfs_log.c +7 -0
@@ -1219,6 +1221,13 @@ xlog_alloc_log(xfs_mount_t	*mp,
 		prev_iclog = iclog;
 
 		bp = xfs_buf_get_noaddr(log->l_iclog_size, mp->m_logdev_targp);
+		if (!iclog || !bp) {
+			if (iclog)
+				kmem_free(iclog, sizeof(xlog_in_core_t));
+			log->l_iclog_bufs = i;
+			xlog_dealloc_log(log);
+			return NULL;
+		}

Please check for iclog beeing NULL before trying to allocate the buffer, and switch it to KM_MAYFAIL. Given that there are two failing cases now it would make sense to have goto-unwinding here.

Also once you touch the memory allocation feel free to remove the useless casts of their return values.

fs/xfs/xfs_mount.c xfs_mountfs( · line 1010

Quoted 9 lines

Index: linux-2.6.24.noarch/fs/xfs/xfs_mount.c
===================================================================

fs/xfs/xfs_mount.c +1 -0
@@ -1007,6 +1007,7 @@ xfs_mountfs(
 			error = XFS_ERROR(EINVAL);
 			goto error1;
 		}
+		uuid_mounted = 1;

How is this related to the rest of the patch?

#2 lore raw
Quoted 6 lines · Christoph Hellwig

fs/xfs/xfs_log.c xfs_log_mount(xfs_mount_t *mp, · line 517

Quoted 3 lines · Eric Sandeen
fs/xfs/xfs_log.c +2 -0
 	mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
+	if (!mp->m_log)
+		return ENOMEM;

Currently there's no allocations in there that should be able to fail.

Well, actually...

Quoted 6 lines

But actually marking these KM_MAYFAIL would be a good idea.

fs/xfs/xfs_log.c xlog_alloc_log(xfs_mount_t *mp, · line 1223

Quoted 4 lines
fs/xfs/xfs_log.c +0 -0
@@ -1219,6 +1221,13 @@ xlog_alloc_log(xfs_mount_t	*mp,
 		prev_iclog = iclog;
 
 		bp = xfs_buf_get_noaddr(log->l_iclog_size, mp->m_logdev_targp);

This was failing for him I think.

Quoted 11 lines

fs/xfs/xfs_log.c xlog_alloc_log(xfs_mount_t *mp, · line 1230

Quoted 7 lines
fs/xfs/xfs_log.c +7 -0
+		if (!iclog || !bp) {
+			if (iclog)
+				kmem_free(iclog, sizeof(xlog_in_core_t));
+			log->l_iclog_bufs = i;
+			xlog_dealloc_log(log);
+			return NULL;
+		}

Please check for iclog beeing NULL before trying to allocate the buffer, and switch it to KM_MAYFAIL. Given that there are two failing cases now it would make sense to have goto-unwinding here.

hmm yeah probably so.

Quoted 14 lines

Also once you touch the memory allocation feel free to remove the useless casts of their return values.

fs/xfs/xfs_mount.c xfs_mountfs( · line 1010

Quoted 9 lines

Index: linux-2.6.24.noarch/fs/xfs/xfs_mount.c
===================================================================

fs/xfs/xfs_mount.c +1 -0
@@ -1007,6 +1007,7 @@ xfs_mountfs(
 			error = XFS_ERROR(EINVAL);
 			goto error1;
 		}
+		uuid_mounted = 1;

How is this related to the rest of the patch?

if we errored out, we returned from mount w/o taking the uuid back out of the table.

-Eric

#3 lore raw
Quoted 13 lines · Eric Sandeen
Quoted 10 lines · Christoph Hellwig

fs/xfs/xfs_mount.c xfs_mountfs( · line 1010

Quoted 9 lines

Index: linux-2.6.24.noarch/fs/xfs/xfs_mount.c
===================================================================

fs/xfs/xfs_mount.c +1 -0
@@ -1007,6 +1007,7 @@ xfs_mountfs(
 			error = XFS_ERROR(EINVAL);
 			goto error1;
 		}
+		uuid_mounted = 1;

How is this related to the rest of the patch?

Quoted 2 lines

if we errored out, we returned from mount w/o taking the uuid back out of the table.

er, I must have messed up the tree, that's already there isn't it...

Let me respin this one... :)

-Eric