pseudofs.c (168637) | pseudofs.c (168720) |
---|---|
1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs.c 168637 2007-04-11 22:40:57Z des $"); | 30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs.c 168720 2007-04-14 14:08:30Z des $"); |
31 32#include "opt_pseudofs.h" 33 34#include <sys/param.h> 35#include <sys/kernel.h> 36#include <sys/systm.h> 37#include <sys/lock.h> 38#include <sys/malloc.h> --- 29 unchanged lines hidden (view full) --- 68 ("%s(): parent has no pn_info", __func__)); 69 KASSERT(parent->pn_type == pfstype_dir || 70 parent->pn_type == pfstype_procdir || 71 parent->pn_type == pfstype_root, 72 ("%s(): parent is not a directory", __func__)); 73 74 /* XXX should check for duplicate names etc. */ 75 | 31 32#include "opt_pseudofs.h" 33 34#include <sys/param.h> 35#include <sys/kernel.h> 36#include <sys/systm.h> 37#include <sys/lock.h> 38#include <sys/malloc.h> --- 29 unchanged lines hidden (view full) --- 68 ("%s(): parent has no pn_info", __func__)); 69 KASSERT(parent->pn_type == pfstype_dir || 70 parent->pn_type == pfstype_procdir || 71 parent->pn_type == pfstype_root, 72 ("%s(): parent is not a directory", __func__)); 73 74 /* XXX should check for duplicate names etc. */ 75 |
76 mtx_lock(&parent->pn_info->pi_mutex); | |
77 node->pn_info = parent->pn_info; 78 node->pn_parent = parent; 79 node->pn_next = parent->pn_nodes; 80 parent->pn_nodes = node; 81 /* Propagate flag to all child nodes (and thus their vnodes) */ 82 if ((parent->pn_flags & PFS_PROCDEP) != 0) 83 node->pn_flags |= PFS_PROCDEP; | 76 node->pn_info = parent->pn_info; 77 node->pn_parent = parent; 78 node->pn_next = parent->pn_nodes; 79 parent->pn_nodes = node; 80 /* Propagate flag to all child nodes (and thus their vnodes) */ 81 if ((parent->pn_flags & PFS_PROCDEP) != 0) 82 node->pn_flags |= PFS_PROCDEP; |
84 mtx_unlock(&parent->pn_info->pi_mutex); | |
85 86 return (0); 87} 88 89/* 90 * Add . and .. to a directory 91 */ 92static int --- 112 unchanged lines hidden (view full) --- 205 */ 206struct pfs_node * 207pfs_find_node(struct pfs_node *parent, const char *name) 208{ 209 struct pfs_node *node; 210 211 for (node = parent->pn_nodes; node != NULL; node = node->pn_next) 212 if (strcmp(node->pn_name, name) == 0) | 83 84 return (0); 85} 86 87/* 88 * Add . and .. to a directory 89 */ 90static int --- 112 unchanged lines hidden (view full) --- 203 */ 204struct pfs_node * 205pfs_find_node(struct pfs_node *parent, const char *name) 206{ 207 struct pfs_node *node; 208 209 for (node = parent->pn_nodes; node != NULL; node = node->pn_next) 210 if (strcmp(node->pn_name, name) == 0) |
213 return (node); 214 return (NULL); | 211 break; 212 return (node); |
215} 216 217/* 218 * Destroy a node or a tree of nodes 219 */ 220int 221pfs_destroy(struct pfs_node *node) 222{ | 213} 214 215/* 216 * Destroy a node or a tree of nodes 217 */ 218int 219pfs_destroy(struct pfs_node *node) 220{ |
223 struct pfs_node *parent, *rover; | 221 struct pfs_node *parent, **rover; |
224 225 KASSERT(node != NULL, 226 ("%s(): node is NULL", __func__)); 227 KASSERT(node->pn_info != NULL, 228 ("%s(): node has no pn_info", __func__)); 229 230 /* destroy children */ 231 if (node->pn_type == pfstype_dir || 232 node->pn_type == pfstype_procdir || 233 node->pn_type == pfstype_root) 234 while (node->pn_nodes != NULL) 235 pfs_destroy(node->pn_nodes); 236 237 /* unlink from parent */ 238 if ((parent = node->pn_parent) != NULL) { 239 KASSERT(parent->pn_info == node->pn_info, 240 ("%s(): parent has different pn_info", __func__)); | 222 223 KASSERT(node != NULL, 224 ("%s(): node is NULL", __func__)); 225 KASSERT(node->pn_info != NULL, 226 ("%s(): node has no pn_info", __func__)); 227 228 /* destroy children */ 229 if (node->pn_type == pfstype_dir || 230 node->pn_type == pfstype_procdir || 231 node->pn_type == pfstype_root) 232 while (node->pn_nodes != NULL) 233 pfs_destroy(node->pn_nodes); 234 235 /* unlink from parent */ 236 if ((parent = node->pn_parent) != NULL) { 237 KASSERT(parent->pn_info == node->pn_info, 238 ("%s(): parent has different pn_info", __func__)); |
241 mtx_lock(&node->pn_info->pi_mutex); 242 if (parent->pn_nodes == node) { 243 parent->pn_nodes = node->pn_next; 244 } else { 245 rover = parent->pn_nodes; 246 while (rover->pn_next != NULL) { 247 if (rover->pn_next == node) { 248 rover->pn_next = node->pn_next; 249 break; 250 } 251 rover = rover->pn_next; | 239 rover = &parent->pn_nodes; 240 while (*rover != NULL) { 241 if (*rover == node) { 242 *rover = node->pn_next; 243 break; |
252 } | 244 } |
245 rover = &(*rover)->pn_next; |
|
253 } | 246 } |
254 mtx_unlock(&node->pn_info->pi_mutex); | |
255 } 256 257 /* callback to free any private resources */ 258 if (node->pn_destroy != NULL) 259 (node->pn_destroy)(node); 260 261 /* revoke fileno and vnodes and release memory */ 262 if (node->pn_fileno) | 247 } 248 249 /* callback to free any private resources */ 250 if (node->pn_destroy != NULL) 251 (node->pn_destroy)(node); 252 253 /* revoke fileno and vnodes and release memory */ 254 if (node->pn_fileno) |
263 pfs_fileno_free(node->pn_info, node); | 255 pfs_fileno_free(node); |
264 pfs_purge(node); 265 FREE(node, M_PFSNODES); 266 267 return (0); 268} 269 270/* 271 * Mount a pseudofs instance --- 81 unchanged lines hidden (view full) --- 353 * Initialize a pseudofs instance 354 */ 355int 356pfs_init(struct pfs_info *pi, struct vfsconf *vfc) 357{ 358 struct pfs_node *root; 359 int error; 360 | 256 pfs_purge(node); 257 FREE(node, M_PFSNODES); 258 259 return (0); 260} 261 262/* 263 * Mount a pseudofs instance --- 81 unchanged lines hidden (view full) --- 345 * Initialize a pseudofs instance 346 */ 347int 348pfs_init(struct pfs_info *pi, struct vfsconf *vfc) 349{ 350 struct pfs_node *root; 351 int error; 352 |
361 mtx_init(&pi->pi_mutex, "pseudofs", NULL, MTX_DEF); | 353 mtx_assert(&Giant, MA_OWNED); |
362 363 /* set up the root diretory */ 364 MALLOC(root, struct pfs_node *, sizeof *root, 365 M_PFSNODES, M_WAITOK|M_ZERO); 366 root->pn_type = pfstype_root; 367 root->pn_name[0] = '/'; 368 root->pn_info = pi; 369 if (_pfs_fixup_dir(root) != 0) { 370 FREE(root, M_PFSNODES); 371 return (ENODEV); /* XXX not really the right errno */ 372 } 373 pi->pi_root = root; 374 375 /* construct file hierarchy */ 376 error = (pi->pi_init)(pi, vfc); 377 if (error) { 378 pfs_destroy(root); 379 pi->pi_root = NULL; | 354 355 /* set up the root diretory */ 356 MALLOC(root, struct pfs_node *, sizeof *root, 357 M_PFSNODES, M_WAITOK|M_ZERO); 358 root->pn_type = pfstype_root; 359 root->pn_name[0] = '/'; 360 root->pn_info = pi; 361 if (_pfs_fixup_dir(root) != 0) { 362 FREE(root, M_PFSNODES); 363 return (ENODEV); /* XXX not really the right errno */ 364 } 365 pi->pi_root = root; 366 367 /* construct file hierarchy */ 368 error = (pi->pi_init)(pi, vfc); 369 if (error) { 370 pfs_destroy(root); 371 pi->pi_root = NULL; |
380 mtx_destroy(&pi->pi_mutex); | |
381 return (error); 382 } 383 384 pfs_fileno_init(pi); 385 if (bootverbose) 386 printf("%s registered\n", pi->pi_name); 387 return (0); 388} 389 390/* 391 * Destroy a pseudofs instance 392 */ 393int 394pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc) 395{ 396 int error; 397 | 372 return (error); 373 } 374 375 pfs_fileno_init(pi); 376 if (bootverbose) 377 printf("%s registered\n", pi->pi_name); 378 return (0); 379} 380 381/* 382 * Destroy a pseudofs instance 383 */ 384int 385pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc) 386{ 387 int error; 388 |
389 mtx_assert(&Giant, MA_OWNED); 390 |
|
398 pfs_destroy(pi->pi_root); 399 pi->pi_root = NULL; 400 pfs_fileno_uninit(pi); | 391 pfs_destroy(pi->pi_root); 392 pi->pi_root = NULL; 393 pfs_fileno_uninit(pi); |
401 mtx_destroy(&pi->pi_mutex); | |
402 if (bootverbose) 403 printf("%s unregistered\n", pi->pi_name); 404 error = (pi->pi_uninit)(pi, vfc); 405 return (error); 406} 407 408/* 409 * Handle load / unload events --- 29 unchanged lines hidden --- | 394 if (bootverbose) 395 printf("%s unregistered\n", pi->pi_name); 396 error = (pi->pi_uninit)(pi, vfc); 397 return (error); 398} 399 400/* 401 * Handle load / unload events --- 29 unchanged lines hidden --- |