sysfile.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * sysfile.c
  5. *
  6. * Initialize, read, write, etc. system files.
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/fs.h>
  26. #include <linux/types.h>
  27. #include <linux/slab.h>
  28. #include <linux/highmem.h>
  29. #define MLOG_MASK_PREFIX ML_INODE
  30. #include <cluster/masklog.h>
  31. #include "ocfs2.h"
  32. #include "alloc.h"
  33. #include "dir.h"
  34. #include "inode.h"
  35. #include "journal.h"
  36. #include "sysfile.h"
  37. #include "buffer_head_io.h"
  38. static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb,
  39. int type,
  40. u32 slot);
  41. static inline int is_global_system_inode(int type);
  42. static inline int is_in_system_inode_array(struct ocfs2_super *osb,
  43. int type,
  44. u32 slot);
  45. static inline int is_global_system_inode(int type)
  46. {
  47. return type >= OCFS2_FIRST_ONLINE_SYSTEM_INODE &&
  48. type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE;
  49. }
  50. static inline int is_in_system_inode_array(struct ocfs2_super *osb,
  51. int type,
  52. u32 slot)
  53. {
  54. return slot == osb->slot_num || is_global_system_inode(type);
  55. }
  56. struct inode *ocfs2_get_system_file_inode(struct ocfs2_super *osb,
  57. int type,
  58. u32 slot)
  59. {
  60. struct inode *inode = NULL;
  61. struct inode **arr = NULL;
  62. /* avoid the lookup if cached in local system file array */
  63. if (is_in_system_inode_array(osb, type, slot))
  64. arr = &(osb->system_inodes[type]);
  65. if (arr && ((inode = *arr) != NULL)) {
  66. /* get a ref in addition to the array ref */
  67. inode = igrab(inode);
  68. BUG_ON(!inode);
  69. return inode;
  70. }
  71. /* this gets one ref thru iget */
  72. inode = _ocfs2_get_system_file_inode(osb, type, slot);
  73. /* add one more if putting into array for first time */
  74. if (arr && inode) {
  75. *arr = igrab(inode);
  76. BUG_ON(!*arr);
  77. }
  78. return inode;
  79. }
  80. static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb,
  81. int type,
  82. u32 slot)
  83. {
  84. char namebuf[40];
  85. struct inode *inode = NULL;
  86. u64 blkno;
  87. int status = 0;
  88. ocfs2_sprintf_system_inode_name(namebuf,
  89. sizeof(namebuf),
  90. type, slot);
  91. status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, namebuf,
  92. strlen(namebuf), &blkno);
  93. if (status < 0) {
  94. goto bail;
  95. }
  96. inode = ocfs2_iget(osb, blkno, OCFS2_FI_FLAG_SYSFILE, type);
  97. if (IS_ERR(inode)) {
  98. mlog_errno(PTR_ERR(inode));
  99. inode = NULL;
  100. goto bail;
  101. }
  102. bail:
  103. return inode;
  104. }