Date: Sat, 25 May 2019 20:24:52 +0000 (UTC) From: Johannes Lundberg <johalun@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348279 - stable/12/sys/fs/pseudofs Message-ID: <201905252024.x4PKOqCC071351@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: johalun Date: Sat May 25 20:24:51 2019 New Revision: 348279 URL: https://svnweb.freebsd.org/changeset/base/348279 Log: MFC r344385: PFS: Bump NAMELEN and don't require clients to be sleepable - debugfs consumers expect to be able to export names more than 48 characters - debugfs consumers expect to be able to hold locks across calls and are able to handle allocation failures Reviewed by: hps@ Sponsored by: iX Systems Differential Revision: https://reviews.freebsd.org/D19256 Modified: stable/12/sys/fs/pseudofs/pseudofs.c stable/12/sys/fs/pseudofs/pseudofs.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/fs/pseudofs/pseudofs.c ============================================================================== --- stable/12/sys/fs/pseudofs/pseudofs.c Sat May 25 19:59:59 2019 (r348278) +++ stable/12/sys/fs/pseudofs/pseudofs.c Sat May 25 20:24:51 2019 (r348279) @@ -68,15 +68,20 @@ SYSCTL_INT(_vfs_pfs, OID_AUTO, trace, CTLFLAG_RW, &pfs * Allocate and initialize a node */ static struct pfs_node * -pfs_alloc_node(struct pfs_info *pi, const char *name, pfs_type_t type) +pfs_alloc_node_flags(struct pfs_info *pi, const char *name, pfs_type_t type, int flags) { struct pfs_node *pn; + int malloc_flags; KASSERT(strlen(name) < PFS_NAMELEN, ("%s(): node name is too long", __func__)); - - pn = malloc(sizeof *pn, - M_PFSNODES, M_WAITOK|M_ZERO); + if (flags & PFS_NOWAIT) + malloc_flags = M_NOWAIT | M_ZERO; + else + malloc_flags = M_WAITOK | M_ZERO; + pn = malloc(sizeof *pn, M_PFSNODES, malloc_flags); + if (pn == NULL) + return (NULL); mtx_init(&pn->pn_mutex, "pfs_node", NULL, MTX_DEF | MTX_DUPOK); strlcpy(pn->pn_name, name, sizeof pn->pn_name); pn->pn_type = type; @@ -84,6 +89,12 @@ pfs_alloc_node(struct pfs_info *pi, const char *name, return (pn); } +static struct pfs_node * +pfs_alloc_node(struct pfs_info *pi, const char *name, pfs_type_t type) +{ + return (pfs_alloc_node_flags(pi, name, type, 0)); +} + /* * Add a node to a directory */ @@ -160,15 +171,29 @@ pfs_detach_node(struct pfs_node *pn) /* * Add . and .. to a directory */ +static int +pfs_fixup_dir_flags(struct pfs_node *parent, int flags) +{ + struct pfs_node *dot, *dotdot; + + dot = pfs_alloc_node_flags(parent->pn_info, ".", pfstype_this, flags); + if (dot == NULL) + return (ENOMEM); + dotdot = pfs_alloc_node_flags(parent->pn_info, "..", pfstype_parent, flags); + if (dotdot == NULL) { + pfs_destroy(dot); + return (ENOMEM); + } + pfs_add_node(parent, dot); + pfs_add_node(parent, dotdot); + return (0); +} + static void pfs_fixup_dir(struct pfs_node *parent) { - struct pfs_node *pn; - pn = pfs_alloc_node(parent->pn_info, ".", pfstype_this); - pfs_add_node(parent, pn); - pn = pfs_alloc_node(parent->pn_info, "..", pfstype_parent); - pfs_add_node(parent, pn); + pfs_fixup_dir_flags(parent, 0); } /* @@ -180,16 +205,22 @@ pfs_create_dir(struct pfs_node *parent, const char *na int flags) { struct pfs_node *pn; + int rc; - pn = pfs_alloc_node(parent->pn_info, name, - (flags & PFS_PROCDEP) ? pfstype_procdir : pfstype_dir); + pn = pfs_alloc_node_flags(parent->pn_info, name, + (flags & PFS_PROCDEP) ? pfstype_procdir : pfstype_dir, flags); + if (pn == NULL) + return (NULL); pn->pn_attr = attr; pn->pn_vis = vis; pn->pn_destroy = destroy; pn->pn_flags = flags; pfs_add_node(parent, pn); - pfs_fixup_dir(pn); - + rc = pfs_fixup_dir_flags(pn, flags); + if (rc) { + pfs_destroy(pn); + return (NULL); + } return (pn); } @@ -203,7 +234,9 @@ pfs_create_file(struct pfs_node *parent, const char *n { struct pfs_node *pn; - pn = pfs_alloc_node(parent->pn_info, name, pfstype_file); + pn = pfs_alloc_node_flags(parent->pn_info, name, pfstype_file, flags); + if (pn == NULL) + return (NULL); pn->pn_fill = fill; pn->pn_attr = attr; pn->pn_vis = vis; @@ -224,7 +257,9 @@ pfs_create_link(struct pfs_node *parent, const char *n { struct pfs_node *pn; - pn = pfs_alloc_node(parent->pn_info, name, pfstype_symlink); + pn = pfs_alloc_node_flags(parent->pn_info, name, pfstype_symlink, flags); + if (pn == NULL) + return (NULL); pn->pn_fill = fill; pn->pn_attr = attr; pn->pn_vis = vis; Modified: stable/12/sys/fs/pseudofs/pseudofs.h ============================================================================== --- stable/12/sys/fs/pseudofs/pseudofs.h Sat May 25 19:59:59 2019 (r348278) +++ stable/12/sys/fs/pseudofs/pseudofs.h Sat May 25 20:24:51 2019 (r348279) @@ -52,7 +52,7 @@ struct vnode; /* * Limits and constants */ -#define PFS_NAMELEN 48 +#define PFS_NAMELEN 128 #define PFS_FSNAMELEN 16 /* equal to MFSNAMELEN */ #define PFS_DELEN (offsetof(struct dirent, d_name) + PFS_NAMELEN) @@ -77,6 +77,7 @@ typedef enum { #define PFS_RAWWR 0x0008 /* raw writer */ #define PFS_RAW (PFS_RAWRD|PFS_RAWWR) #define PFS_PROCDEP 0x0010 /* process-dependent */ +#define PFS_NOWAIT 0x0020 /* allow malloc to fail */ /* * Data structures
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905252024.x4PKOqCC071351>