ftl: should pre-allocate eblock for car case
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
This commit is contained in:
parent
97d684847b
commit
702068e62c
@ -215,6 +215,18 @@ static int ftl_open(FAR struct inode *inode)
|
||||
DEBUGASSERT(inode->i_private);
|
||||
dev = inode->i_private;
|
||||
|
||||
if (dev->refs == 0)
|
||||
{
|
||||
/* Allocate one, in-memory erase block buffer */
|
||||
|
||||
dev->eblock = kmm_malloc(dev->geo.erasesize);
|
||||
if (!dev->eblock)
|
||||
{
|
||||
ferr("ERROR: Failed to allocate an erase block buffer\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
dev->refs++;
|
||||
return OK;
|
||||
}
|
||||
@ -237,18 +249,21 @@ static int ftl_close(FAR struct inode *inode)
|
||||
rwb_flush(&dev->rwb);
|
||||
#endif
|
||||
|
||||
if (--dev->refs == 0 && dev->unlinked)
|
||||
if (--dev->refs == 0)
|
||||
{
|
||||
#ifdef FTL_HAVE_RWBUFFER
|
||||
rwb_uninitialize(&dev->rwb);
|
||||
#endif
|
||||
if (dev->eblock)
|
||||
{
|
||||
kmm_free(dev->eblock);
|
||||
}
|
||||
|
||||
if (dev->unlinked)
|
||||
{
|
||||
#ifdef FTL_HAVE_RWBUFFER
|
||||
rwb_uninitialize(&dev->rwb);
|
||||
#endif
|
||||
kmm_free(dev);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -461,18 +476,6 @@ static ssize_t ftl_read(FAR struct inode *inode, unsigned char *buffer,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ftl_alloc_eblock(FAR struct ftl_struct_s *dev)
|
||||
{
|
||||
if (dev->eblock == NULL)
|
||||
{
|
||||
/* Allocate one, in-memory erase block buffer */
|
||||
|
||||
dev->eblock = kmm_malloc(dev->geo.erasesize);
|
||||
}
|
||||
|
||||
return dev->eblock != NULL ? OK : -ENOMEM;
|
||||
}
|
||||
|
||||
static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
off_t startblock, size_t nblocks)
|
||||
{
|
||||
@ -504,13 +507,6 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
|
||||
bool short_write = (remaining < (alignedblock - startblock));
|
||||
|
||||
ret = ftl_alloc_eblock(dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to allocate an erase block buffer\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read the full erase block into the buffer */
|
||||
|
||||
rwblock = startblock & ~mask;
|
||||
@ -604,13 +600,6 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
|
||||
if (remaining > 0)
|
||||
{
|
||||
ret = ftl_alloc_eblock(dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to allocate an erase block buffer\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read the full erase block into the buffer */
|
||||
|
||||
nxfrd = ftl_mtd_bread(dev, alignedblock, dev->blkper, dev->eblock);
|
||||
@ -767,10 +756,6 @@ static int ftl_unlink(FAR struct inode *inode)
|
||||
#ifdef FTL_HAVE_RWBUFFER
|
||||
rwb_uninitialize(&dev->rwb);
|
||||
#endif
|
||||
if (dev->eblock)
|
||||
{
|
||||
kmm_free(dev->eblock);
|
||||
}
|
||||
|
||||
kmm_free(dev);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user