+// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
* All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <sys/stat.h>
#include "xfs_inode.h"
#include "xfs_trans.h"
#include "xfs_rmap_btree.h"
+#include "xfs_refcount_btree.h"
#include "libxfs.h" /* for now */
int use_xfs_buf_lock; /* global flag: use xfs_buf_t locks for MT */
-static void manage_zones(int); /* setup global zones */
-
-kmem_zone_t *xfs_inode_zone;
+static int manage_zones(int); /* setup/teardown global zones */
/*
* dev_map - map open devices to fd.
static int
check_isactive(char *name, char *block, int fatal)
{
- struct stat64 st;
+ struct stat st;
- if (stat64(block, &st) < 0)
+ if (stat(block, &st) < 0)
return 0;
if ((st.st_mode & S_IFMT) != S_IFBLK)
return 0;
dev_t dev;
int fd, d, flags;
int readonly, dio, excl;
- struct stat64 statb;
+ struct stat statb;
readonly = (xflags & LIBXFS_ISREADONLY);
excl = (xflags & LIBXFS_EXCLUSIVELY) && !creat;
exit(1);
}
- if (fstat64(fd, &statb) < 0) {
+ if (fstat(fd, &statb) < 0) {
fprintf(stderr, _("%s: cannot stat %s: %s\n"),
progname, path, strerror(errno));
exit(1);
int readonly = (flags & LIBXFS_ISREADONLY);
int inactive = (flags & LIBXFS_ISINACTIVE);
int dangerously = (flags & LIBXFS_DANGEROUSLY);
- struct stat64 stbuf;
+ struct stat stbuf;
- if (stat64(path, &stbuf) < 0) {
+ if (stat(path, &stbuf) < 0) {
perror(path);
return 0;
}
libxfs_init(libxfs_init_t *a)
{
char *blockfile;
- char curdir[MAXPATHLEN];
char *dname;
char dpath[25];
int fd;
char *logname;
char logpath[25];
- int needcd;
char *rawfile;
char *rtname;
char rtpath[25];
a->dsize = a->lbsize = a->rtbsize = 0;
a->dbsize = a->logBBsize = a->logBBstart = a->rtsize = 0;
- (void)getcwd(curdir,MAXPATHLEN);
- needcd = 0;
fd = -1;
flags = (a->isreadonly | a->isdirect);
xfs_extent_free_init_defer_op();
xfs_rmap_update_init_defer_op();
+ xfs_refcount_update_init_defer_op();
+ xfs_bmap_update_init_defer_op();
radix_tree_init();
if (a->volname) {
if(!check_open(a->volname,flags,&rawfile,&blockfile))
goto done;
- needcd = 1;
fd = open(rawfile, O_RDONLY);
dname = a->dname = a->volname;
a->volname = NULL;
}
if (dname) {
- if (dname[0] != '/' && needcd)
- chdir(curdir);
if (a->disfile) {
a->ddev= libxfs_device_open(dname, a->dcreat, flags,
a->setblksize);
platform_findsizes(rawfile, a->dfd,
&a->dsize, &a->dbsize);
}
- needcd = 1;
} else
a->dsize = 0;
if (logname) {
- if (logname[0] != '/' && needcd)
- chdir(curdir);
if (a->lisfile) {
a->logdev = libxfs_device_open(logname,
a->lcreat, flags, a->setblksize);
platform_findsizes(rawfile, a->logfd,
&a->logBBsize, &a->lbsize);
}
- needcd = 1;
} else
a->logBBsize = 0;
if (rtname) {
- if (rtname[0] != '/' && needcd)
- chdir(curdir);
if (a->risfile) {
a->rtdev = libxfs_device_open(rtname,
a->rcreat, flags, a->setblksize);
platform_findsizes(rawfile, a->rtfd,
&a->rtsize, &a->rtbsize);
}
- needcd = 1;
} else
a->rtsize = 0;
if (a->dsize < 0) {
progname);
goto done;
}
- if (needcd)
- chdir(curdir);
if (!libxfs_bhash_size)
libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp);
libxfs_bcache = cache_init(a->bcache_flags, libxfs_bhash_size,
/*
* Initialize/destroy all of the zone allocators we use.
*/
-static void
+static int
manage_zones(int release)
{
extern kmem_zone_t *xfs_buf_zone;
extern kmem_zone_t *xfs_ili_zone;
+ extern kmem_zone_t *xfs_inode_zone;
extern kmem_zone_t *xfs_ifork_zone;
extern kmem_zone_t *xfs_buf_item_zone;
extern kmem_zone_t *xfs_da_state_zone;
extern kmem_zone_t *xfs_btree_cur_zone;
extern kmem_zone_t *xfs_bmap_free_item_zone;
- extern kmem_zone_t *xfs_log_item_desc_zone;
+ extern kmem_zone_t *xfs_trans_zone;
extern void xfs_dir_startup();
if (release) { /* free zone allocation */
- kmem_free(xfs_buf_zone);
- kmem_free(xfs_inode_zone);
- kmem_free(xfs_ifork_zone);
- kmem_free(xfs_buf_item_zone);
- kmem_free(xfs_da_state_zone);
- kmem_free(xfs_btree_cur_zone);
- kmem_free(xfs_bmap_free_item_zone);
- kmem_free(xfs_log_item_desc_zone);
- return;
+ int leaked = 0;
+
+ leaked += kmem_zone_destroy(xfs_buf_zone);
+ leaked += kmem_zone_destroy(xfs_ili_zone);
+ leaked += kmem_zone_destroy(xfs_inode_zone);
+ leaked += kmem_zone_destroy(xfs_ifork_zone);
+ leaked += kmem_zone_destroy(xfs_buf_item_zone);
+ leaked += kmem_zone_destroy(xfs_da_state_zone);
+ leaked += kmem_zone_destroy(xfs_btree_cur_zone);
+ leaked += kmem_zone_destroy(xfs_bmap_free_item_zone);
+ leaked += kmem_zone_destroy(xfs_trans_zone);
+
+ return leaked;
}
/* otherwise initialise zone allocation */
xfs_buf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buffer");
xfs_bmap_free_item_zone = kmem_zone_init(
sizeof(struct xfs_extent_free_item),
"xfs_bmap_free_item");
- xfs_log_item_desc_zone = kmem_zone_init(
- sizeof(struct xfs_log_item_desc), "xfs_log_item_desc");
+ xfs_trans_zone = kmem_zone_init(
+ sizeof(struct xfs_trans), "xfs_trans");
xfs_dir_startup();
+
+ return 0;
}
/*
* the max inode percentage.
*/
if (mp->m_maxicount) {
- __uint64_t icount;
+ uint64_t icount;
icount = sbp->sb_dblocks * sbp->sb_imax_pct;
do_div(icount, 100);
xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
xfs_ialloc_compute_maxlevels(mp);
xfs_rmapbt_compute_maxlevels(mp);
+ xfs_refcountbt_compute_maxlevels(mp);
if (sbp->sb_imax_pct) {
/* Make sure the maximum inode count is a multiple of the
mp->m_maxicount = 0;
mp->m_inode_cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
+ if (xfs_sb_version_hascrc(&mp->m_sb)) {
+ int new_size = mp->m_inode_cluster_size;
+
+ new_size *= mp->m_sb.sb_inodesize / XFS_DINODE_MIN_SIZE;
+ if (mp->m_sb.sb_inoalignmt >= XFS_B_TO_FSBT(mp, new_size))
+ mp->m_inode_cluster_size = new_size;
+ }
/*
* Set whether we're using stripe alignment.
return NULL;
}
+ /*
+ * libxfs_initialize_perag will allocate a perag structure for each ag.
+ * If agcount is corrupted and insanely high, this will OOM the box.
+ * If the agount seems (arbitrarily) high, try to read what would be
+ * the last AG, and if that fails for a relatively high agcount, just
+ * read the first one and let the user know to check the geometry.
+ */
+ if (sbp->sb_agcount > 1000000) {
+ bp = libxfs_readbuf(mp->m_dev,
+ XFS_AG_DADDR(mp, sbp->sb_agcount - 1, 0), 1,
+ !(flags & LIBXFS_MOUNT_DEBUGGER), NULL);
+ if (bp->b_error) {
+ fprintf(stderr, _("%s: read of AG %u failed\n"),
+ progname, sbp->sb_agcount);
+ if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+ return NULL;
+ fprintf(stderr, _("%s: limiting reads to AG 0\n"),
+ progname);
+ sbp->sb_agcount = 1;
+ }
+ libxfs_putbuf(bp);
+ }
+
error = libxfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi);
if (error) {
fprintf(stderr, _("%s: perag init failed\n"),
void
libxfs_destroy(void)
{
- manage_zones(1);
+ int leaked;
+
+ /* Free everything from the buffer cache before freeing buffer zone */
+ libxfs_bcache_purge();
+ libxfs_bcache_free();
cache_destroy(libxfs_bcache);
+ leaked = manage_zones(1);
+ if (getenv("LIBXFS_LEAK_CHECK") && leaked)
+ exit(1);
}
int
int
libxfs_nproc(void)
{
- return platform_nproc();
+ int nr;
+
+ nr = platform_nproc();
+ if (nr < 1)
+ nr = 1;
+ return nr;
}
unsigned long