Commit 38f91be5 authored by Jim Harris's avatar Jim Harris Committed by Daniel Verkamp
Browse files

blobfs: cache_insert_buffer() - check count before allocating buffer



This avoids corner case where a buffer gets allocated on the 100th
try.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: If65053d539d458d9a53c8850bbb4cbe4ee84f604
parent 7079a18f
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -1496,18 +1496,20 @@ cache_insert_buffer(struct spdk_file *file, uint64_t offset)
	buf->buf = alloc_cache_memory_buffer(file);
	if (buf->buf == NULL) {
		while (buf->buf == NULL) {
			count++;
			buf->buf = alloc_cache_memory_buffer(file);
			/*
			 * TODO: __free_oldest_cache() should eventually free some buffers.
			 *  Should have a more sophisticated check here, instead of just
			 *  bailing if 100 tries does not result in getting a free buffer.
			 * TODO: alloc_cache_memory_buffer() should eventually free
			 *  some buffers.  Need a more sophisticated check here, instead
			 *  of just bailing if 100 tries does not result in getting a
			 *  free buffer.  This will involve using the sync channel's
			 *  semaphore to block until a buffer becomes available.
			 */
			if (count == 100) {
			if (count++ == 100) {
				SPDK_ERRLOG("could not allocate cache buffer\n");
				assert(false);
				free(buf);
				return NULL;
			}
			buf->buf = alloc_cache_memory_buffer(file);
		}
	}