super.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * super.c
  5. *
  6. * load/unload driver, mount/dismount volumes
  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/module.h>
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/init.h>
  31. #include <linux/random.h>
  32. #include <linux/statfs.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/socket.h>
  36. #include <linux/inet.h>
  37. #include <linux/parser.h>
  38. #include <linux/crc32.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/mount.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/quotaops.h>
  43. #include <linux/smp_lock.h>
  44. #define MLOG_MASK_PREFIX ML_SUPER
  45. #include <cluster/masklog.h>
  46. #include "ocfs2.h"
  47. /* this should be the only file to include a version 1 header */
  48. #include "ocfs1_fs_compat.h"
  49. #include "alloc.h"
  50. #include "blockcheck.h"
  51. #include "dlmglue.h"
  52. #include "export.h"
  53. #include "extent_map.h"
  54. #include "heartbeat.h"
  55. #include "inode.h"
  56. #include "journal.h"
  57. #include "localalloc.h"
  58. #include "namei.h"
  59. #include "slot_map.h"
  60. #include "super.h"
  61. #include "sysfile.h"
  62. #include "uptodate.h"
  63. #include "ver.h"
  64. #include "xattr.h"
  65. #include "quota.h"
  66. #include "refcounttree.h"
  67. #include "suballoc.h"
  68. #include "buffer_head_io.h"
  69. static struct kmem_cache *ocfs2_inode_cachep = NULL;
  70. struct kmem_cache *ocfs2_dquot_cachep;
  71. struct kmem_cache *ocfs2_qf_chunk_cachep;
  72. /* OCFS2 needs to schedule several differnt types of work which
  73. * require cluster locking, disk I/O, recovery waits, etc. Since these
  74. * types of work tend to be heavy we avoid using the kernel events
  75. * workqueue and schedule on our own. */
  76. struct workqueue_struct *ocfs2_wq = NULL;
  77. static struct dentry *ocfs2_debugfs_root = NULL;
  78. MODULE_AUTHOR("Oracle");
  79. MODULE_LICENSE("GPL");
  80. struct mount_options
  81. {
  82. unsigned long commit_interval;
  83. unsigned long mount_opt;
  84. unsigned int atime_quantum;
  85. signed short slot;
  86. int localalloc_opt;
  87. unsigned int resv_level;
  88. int dir_resv_level;
  89. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  90. };
  91. static int ocfs2_parse_options(struct super_block *sb, char *options,
  92. struct mount_options *mopt,
  93. int is_remount);
  94. static int ocfs2_check_set_options(struct super_block *sb,
  95. struct mount_options *options);
  96. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
  97. static void ocfs2_put_super(struct super_block *sb);
  98. static int ocfs2_mount_volume(struct super_block *sb);
  99. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  100. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  101. static int ocfs2_initialize_mem_caches(void);
  102. static void ocfs2_free_mem_caches(void);
  103. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  104. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  105. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  106. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  107. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  108. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  109. static int ocfs2_check_volume(struct ocfs2_super *osb);
  110. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  111. struct buffer_head *bh,
  112. u32 sectsize,
  113. struct ocfs2_blockcheck_stats *stats);
  114. static int ocfs2_initialize_super(struct super_block *sb,
  115. struct buffer_head *bh,
  116. int sector_size,
  117. struct ocfs2_blockcheck_stats *stats);
  118. static int ocfs2_get_sector(struct super_block *sb,
  119. struct buffer_head **bh,
  120. int block,
  121. int sect_size);
  122. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  123. static void ocfs2_destroy_inode(struct inode *inode);
  124. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  125. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  126. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  127. static const struct super_operations ocfs2_sops = {
  128. .statfs = ocfs2_statfs,
  129. .alloc_inode = ocfs2_alloc_inode,
  130. .destroy_inode = ocfs2_destroy_inode,
  131. .drop_inode = ocfs2_drop_inode,
  132. .clear_inode = ocfs2_clear_inode,
  133. .delete_inode = ocfs2_delete_inode,
  134. .sync_fs = ocfs2_sync_fs,
  135. .put_super = ocfs2_put_super,
  136. .remount_fs = ocfs2_remount,
  137. .show_options = ocfs2_show_options,
  138. .quota_read = ocfs2_quota_read,
  139. .quota_write = ocfs2_quota_write,
  140. };
  141. enum {
  142. Opt_barrier,
  143. Opt_err_panic,
  144. Opt_err_ro,
  145. Opt_intr,
  146. Opt_nointr,
  147. Opt_hb_none,
  148. Opt_hb_local,
  149. Opt_data_ordered,
  150. Opt_data_writeback,
  151. Opt_atime_quantum,
  152. Opt_slot,
  153. Opt_commit,
  154. Opt_localalloc,
  155. Opt_localflocks,
  156. Opt_stack,
  157. Opt_user_xattr,
  158. Opt_nouser_xattr,
  159. Opt_inode64,
  160. Opt_acl,
  161. Opt_noacl,
  162. Opt_usrquota,
  163. Opt_grpquota,
  164. Opt_resv_level,
  165. Opt_dir_resv_level,
  166. Opt_err,
  167. };
  168. static const match_table_t tokens = {
  169. {Opt_barrier, "barrier=%u"},
  170. {Opt_err_panic, "errors=panic"},
  171. {Opt_err_ro, "errors=remount-ro"},
  172. {Opt_intr, "intr"},
  173. {Opt_nointr, "nointr"},
  174. {Opt_hb_none, OCFS2_HB_NONE},
  175. {Opt_hb_local, OCFS2_HB_LOCAL},
  176. {Opt_data_ordered, "data=ordered"},
  177. {Opt_data_writeback, "data=writeback"},
  178. {Opt_atime_quantum, "atime_quantum=%u"},
  179. {Opt_slot, "preferred_slot=%u"},
  180. {Opt_commit, "commit=%u"},
  181. {Opt_localalloc, "localalloc=%d"},
  182. {Opt_localflocks, "localflocks"},
  183. {Opt_stack, "cluster_stack=%s"},
  184. {Opt_user_xattr, "user_xattr"},
  185. {Opt_nouser_xattr, "nouser_xattr"},
  186. {Opt_inode64, "inode64"},
  187. {Opt_acl, "acl"},
  188. {Opt_noacl, "noacl"},
  189. {Opt_usrquota, "usrquota"},
  190. {Opt_grpquota, "grpquota"},
  191. {Opt_resv_level, "resv_level=%u"},
  192. {Opt_dir_resv_level, "dir_resv_level=%u"},
  193. {Opt_err, NULL}
  194. };
  195. #ifdef CONFIG_DEBUG_FS
  196. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  197. {
  198. struct ocfs2_cluster_connection *cconn = osb->cconn;
  199. struct ocfs2_recovery_map *rm = osb->recovery_map;
  200. struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  201. int i, out = 0;
  202. out += snprintf(buf + out, len - out,
  203. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  204. "Device", osb->dev_str, osb->uuid_str,
  205. osb->fs_generation, osb->vol_label);
  206. out += snprintf(buf + out, len - out,
  207. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  208. atomic_read(&osb->vol_state), osb->osb_flags);
  209. out += snprintf(buf + out, len - out,
  210. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  211. osb->sb->s_blocksize, osb->s_clustersize);
  212. out += snprintf(buf + out, len - out,
  213. "%10s => Compat: 0x%X Incompat: 0x%X "
  214. "ROcompat: 0x%X\n",
  215. "Features", osb->s_feature_compat,
  216. osb->s_feature_incompat, osb->s_feature_ro_compat);
  217. out += snprintf(buf + out, len - out,
  218. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  219. osb->s_mount_opt, osb->s_atime_quantum);
  220. if (cconn) {
  221. out += snprintf(buf + out, len - out,
  222. "%10s => Stack: %s Name: %*s "
  223. "Version: %d.%d\n", "Cluster",
  224. (*osb->osb_cluster_stack == '\0' ?
  225. "o2cb" : osb->osb_cluster_stack),
  226. cconn->cc_namelen, cconn->cc_name,
  227. cconn->cc_version.pv_major,
  228. cconn->cc_version.pv_minor);
  229. }
  230. spin_lock(&osb->dc_task_lock);
  231. out += snprintf(buf + out, len - out,
  232. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  233. "WorkSeq: %lu\n", "DownCnvt",
  234. (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
  235. osb->blocked_lock_count, osb->dc_wake_sequence,
  236. osb->dc_work_sequence);
  237. spin_unlock(&osb->dc_task_lock);
  238. spin_lock(&osb->osb_lock);
  239. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  240. "Recovery",
  241. (osb->recovery_thread_task ?
  242. task_pid_nr(osb->recovery_thread_task) : -1));
  243. if (rm->rm_used == 0)
  244. out += snprintf(buf + out, len - out, " None\n");
  245. else {
  246. for (i = 0; i < rm->rm_used; i++)
  247. out += snprintf(buf + out, len - out, " %d",
  248. rm->rm_entries[i]);
  249. out += snprintf(buf + out, len - out, "\n");
  250. }
  251. spin_unlock(&osb->osb_lock);
  252. out += snprintf(buf + out, len - out,
  253. "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
  254. (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  255. osb->osb_commit_interval,
  256. atomic_read(&osb->needs_checkpoint));
  257. out += snprintf(buf + out, len - out,
  258. "%10s => State: %d TxnId: %lu NumTxns: %d\n",
  259. "Journal", osb->journal->j_state,
  260. osb->journal->j_trans_id,
  261. atomic_read(&osb->journal->j_num_trans));
  262. out += snprintf(buf + out, len - out,
  263. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  264. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  265. "Stats",
  266. atomic_read(&osb->alloc_stats.bitmap_data),
  267. atomic_read(&osb->alloc_stats.local_data),
  268. atomic_read(&osb->alloc_stats.bg_allocs),
  269. atomic_read(&osb->alloc_stats.moves),
  270. atomic_read(&osb->alloc_stats.bg_extends));
  271. out += snprintf(buf + out, len - out,
  272. "%10s => State: %u Descriptor: %llu Size: %u bits "
  273. "Default: %u bits\n",
  274. "LocalAlloc", osb->local_alloc_state,
  275. (unsigned long long)osb->la_last_gd,
  276. osb->local_alloc_bits, osb->local_alloc_default_bits);
  277. spin_lock(&osb->osb_lock);
  278. out += snprintf(buf + out, len - out,
  279. "%10s => InodeSlot: %d StolenInodes: %d, "
  280. "MetaSlot: %d StolenMeta: %d\n", "Steal",
  281. osb->s_inode_steal_slot,
  282. atomic_read(&osb->s_num_inodes_stolen),
  283. osb->s_meta_steal_slot,
  284. atomic_read(&osb->s_num_meta_stolen));
  285. spin_unlock(&osb->osb_lock);
  286. out += snprintf(buf + out, len - out, "OrphanScan => ");
  287. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  288. os->os_count, os->os_seqno);
  289. out += snprintf(buf + out, len - out, " Last Scan: ");
  290. if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  291. out += snprintf(buf + out, len - out, "Disabled\n");
  292. else
  293. out += snprintf(buf + out, len - out, "%lu seconds ago\n",
  294. (get_seconds() - os->os_scantime.tv_sec));
  295. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  296. "Slots", "Num", "RecoGen");
  297. for (i = 0; i < osb->max_slots; ++i) {
  298. out += snprintf(buf + out, len - out,
  299. "%10s %c %3d %10d\n",
  300. " ",
  301. (i == osb->slot_num ? '*' : ' '),
  302. i, osb->slot_recovery_generations[i]);
  303. }
  304. return out;
  305. }
  306. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  307. {
  308. struct ocfs2_super *osb = inode->i_private;
  309. char *buf = NULL;
  310. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  311. if (!buf)
  312. goto bail;
  313. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  314. file->private_data = buf;
  315. return 0;
  316. bail:
  317. return -ENOMEM;
  318. }
  319. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  320. {
  321. kfree(file->private_data);
  322. return 0;
  323. }
  324. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  325. size_t nbytes, loff_t *ppos)
  326. {
  327. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  328. i_size_read(file->f_mapping->host));
  329. }
  330. #else
  331. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  332. {
  333. return 0;
  334. }
  335. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  336. {
  337. return 0;
  338. }
  339. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  340. size_t nbytes, loff_t *ppos)
  341. {
  342. return 0;
  343. }
  344. #endif /* CONFIG_DEBUG_FS */
  345. static const struct file_operations ocfs2_osb_debug_fops = {
  346. .open = ocfs2_osb_debug_open,
  347. .release = ocfs2_debug_release,
  348. .read = ocfs2_debug_read,
  349. .llseek = generic_file_llseek,
  350. };
  351. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  352. {
  353. int status;
  354. tid_t target;
  355. struct ocfs2_super *osb = OCFS2_SB(sb);
  356. if (ocfs2_is_hard_readonly(osb))
  357. return -EROFS;
  358. if (wait) {
  359. status = ocfs2_flush_truncate_log(osb);
  360. if (status < 0)
  361. mlog_errno(status);
  362. } else {
  363. ocfs2_schedule_truncate_log_flush(osb, 0);
  364. }
  365. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  366. &target)) {
  367. if (wait)
  368. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  369. target);
  370. }
  371. return 0;
  372. }
  373. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  374. {
  375. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  376. && (ino == USER_QUOTA_SYSTEM_INODE
  377. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  378. return 0;
  379. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  380. && (ino == GROUP_QUOTA_SYSTEM_INODE
  381. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  382. return 0;
  383. return 1;
  384. }
  385. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  386. {
  387. struct inode *new = NULL;
  388. int status = 0;
  389. int i;
  390. mlog_entry_void();
  391. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  392. if (IS_ERR(new)) {
  393. status = PTR_ERR(new);
  394. mlog_errno(status);
  395. goto bail;
  396. }
  397. osb->root_inode = new;
  398. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  399. if (IS_ERR(new)) {
  400. status = PTR_ERR(new);
  401. mlog_errno(status);
  402. goto bail;
  403. }
  404. osb->sys_root_inode = new;
  405. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  406. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  407. if (!ocfs2_need_system_inode(osb, i))
  408. continue;
  409. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  410. if (!new) {
  411. ocfs2_release_system_inodes(osb);
  412. status = -EINVAL;
  413. mlog_errno(status);
  414. /* FIXME: Should ERROR_RO_FS */
  415. mlog(ML_ERROR, "Unable to load system inode %d, "
  416. "possibly corrupt fs?", i);
  417. goto bail;
  418. }
  419. // the array now has one ref, so drop this one
  420. iput(new);
  421. }
  422. bail:
  423. mlog_exit(status);
  424. return status;
  425. }
  426. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  427. {
  428. struct inode *new = NULL;
  429. int status = 0;
  430. int i;
  431. mlog_entry_void();
  432. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  433. i < NUM_SYSTEM_INODES;
  434. i++) {
  435. if (!ocfs2_need_system_inode(osb, i))
  436. continue;
  437. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  438. if (!new) {
  439. ocfs2_release_system_inodes(osb);
  440. status = -EINVAL;
  441. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  442. status, i, osb->slot_num);
  443. goto bail;
  444. }
  445. /* the array now has one ref, so drop this one */
  446. iput(new);
  447. }
  448. bail:
  449. mlog_exit(status);
  450. return status;
  451. }
  452. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  453. {
  454. int i;
  455. struct inode *inode;
  456. mlog_entry_void();
  457. for (i = 0; i < NUM_SYSTEM_INODES; i++) {
  458. inode = osb->system_inodes[i];
  459. if (inode) {
  460. iput(inode);
  461. osb->system_inodes[i] = NULL;
  462. }
  463. }
  464. inode = osb->sys_root_inode;
  465. if (inode) {
  466. iput(inode);
  467. osb->sys_root_inode = NULL;
  468. }
  469. inode = osb->root_inode;
  470. if (inode) {
  471. iput(inode);
  472. osb->root_inode = NULL;
  473. }
  474. mlog_exit(0);
  475. }
  476. /* We're allocating fs objects, use GFP_NOFS */
  477. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  478. {
  479. struct ocfs2_inode_info *oi;
  480. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  481. if (!oi)
  482. return NULL;
  483. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  484. return &oi->vfs_inode;
  485. }
  486. static void ocfs2_destroy_inode(struct inode *inode)
  487. {
  488. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  489. }
  490. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  491. unsigned int cbits)
  492. {
  493. unsigned int bytes = 1 << cbits;
  494. unsigned int trim = bytes;
  495. unsigned int bitshift = 32;
  496. /*
  497. * i_size and all block offsets in ocfs2 are always 64 bits
  498. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  499. * 64 bit platforms, cluster size will be the limiting factor.
  500. */
  501. #if BITS_PER_LONG == 32
  502. # if defined(CONFIG_LBDAF)
  503. BUILD_BUG_ON(sizeof(sector_t) != 8);
  504. /*
  505. * We might be limited by page cache size.
  506. */
  507. if (bytes > PAGE_CACHE_SIZE) {
  508. bytes = PAGE_CACHE_SIZE;
  509. trim = 1;
  510. /*
  511. * Shift by 31 here so that we don't get larger than
  512. * MAX_LFS_FILESIZE
  513. */
  514. bitshift = 31;
  515. }
  516. # else
  517. /*
  518. * We are limited by the size of sector_t. Use block size, as
  519. * that's what we expose to the VFS.
  520. */
  521. bytes = 1 << bbits;
  522. trim = 1;
  523. bitshift = 31;
  524. # endif
  525. #endif
  526. /*
  527. * Trim by a whole cluster when we can actually approach the
  528. * on-disk limits. Otherwise we can overflow i_clusters when
  529. * an extent start is at the max offset.
  530. */
  531. return (((unsigned long long)bytes) << bitshift) - trim;
  532. }
  533. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  534. {
  535. int incompat_features;
  536. int ret = 0;
  537. struct mount_options parsed_options;
  538. struct ocfs2_super *osb = OCFS2_SB(sb);
  539. lock_kernel();
  540. if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
  541. !ocfs2_check_set_options(sb, &parsed_options)) {
  542. ret = -EINVAL;
  543. goto out;
  544. }
  545. if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
  546. (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  547. ret = -EINVAL;
  548. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  549. goto out;
  550. }
  551. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  552. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  553. ret = -EINVAL;
  554. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  555. goto out;
  556. }
  557. /* Probably don't want this on remount; it might
  558. * mess with other nodes */
  559. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  560. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  561. ret = -EINVAL;
  562. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  563. goto out;
  564. }
  565. /* We're going to/from readonly mode. */
  566. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  567. /* Disable quota accounting before remounting RO */
  568. if (*flags & MS_RDONLY) {
  569. ret = ocfs2_susp_quotas(osb, 0);
  570. if (ret < 0)
  571. goto out;
  572. }
  573. /* Lock here so the check of HARD_RO and the potential
  574. * setting of SOFT_RO is atomic. */
  575. spin_lock(&osb->osb_lock);
  576. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  577. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  578. ret = -EROFS;
  579. goto unlock_osb;
  580. }
  581. if (*flags & MS_RDONLY) {
  582. mlog(0, "Going to ro mode.\n");
  583. sb->s_flags |= MS_RDONLY;
  584. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  585. } else {
  586. mlog(0, "Making ro filesystem writeable.\n");
  587. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  588. mlog(ML_ERROR, "Cannot remount RDWR "
  589. "filesystem due to previous errors.\n");
  590. ret = -EROFS;
  591. goto unlock_osb;
  592. }
  593. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  594. if (incompat_features) {
  595. mlog(ML_ERROR, "Cannot remount RDWR because "
  596. "of unsupported optional features "
  597. "(%x).\n", incompat_features);
  598. ret = -EINVAL;
  599. goto unlock_osb;
  600. }
  601. sb->s_flags &= ~MS_RDONLY;
  602. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  603. }
  604. unlock_osb:
  605. spin_unlock(&osb->osb_lock);
  606. /* Enable quota accounting after remounting RW */
  607. if (!ret && !(*flags & MS_RDONLY)) {
  608. if (sb_any_quota_suspended(sb))
  609. ret = ocfs2_susp_quotas(osb, 1);
  610. else
  611. ret = ocfs2_enable_quotas(osb);
  612. if (ret < 0) {
  613. /* Return back changes... */
  614. spin_lock(&osb->osb_lock);
  615. sb->s_flags |= MS_RDONLY;
  616. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  617. spin_unlock(&osb->osb_lock);
  618. goto out;
  619. }
  620. }
  621. }
  622. if (!ret) {
  623. /* Only save off the new mount options in case of a successful
  624. * remount. */
  625. osb->s_mount_opt = parsed_options.mount_opt;
  626. osb->s_atime_quantum = parsed_options.atime_quantum;
  627. osb->preferred_slot = parsed_options.slot;
  628. if (parsed_options.commit_interval)
  629. osb->osb_commit_interval = parsed_options.commit_interval;
  630. if (!ocfs2_is_hard_readonly(osb))
  631. ocfs2_set_journal_params(osb);
  632. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  633. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  634. MS_POSIXACL : 0);
  635. }
  636. out:
  637. unlock_kernel();
  638. return ret;
  639. }
  640. static int ocfs2_sb_probe(struct super_block *sb,
  641. struct buffer_head **bh,
  642. int *sector_size,
  643. struct ocfs2_blockcheck_stats *stats)
  644. {
  645. int status, tmpstat;
  646. struct ocfs1_vol_disk_hdr *hdr;
  647. struct ocfs2_dinode *di;
  648. int blksize;
  649. *bh = NULL;
  650. /* may be > 512 */
  651. *sector_size = bdev_logical_block_size(sb->s_bdev);
  652. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  653. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  654. *sector_size, OCFS2_MAX_BLOCKSIZE);
  655. status = -EINVAL;
  656. goto bail;
  657. }
  658. /* Can this really happen? */
  659. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  660. *sector_size = OCFS2_MIN_BLOCKSIZE;
  661. /* check block zero for old format */
  662. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  663. if (status < 0) {
  664. mlog_errno(status);
  665. goto bail;
  666. }
  667. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  668. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  669. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  670. hdr->major_version, hdr->minor_version);
  671. status = -EINVAL;
  672. }
  673. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  674. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  675. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  676. hdr->signature);
  677. status = -EINVAL;
  678. }
  679. brelse(*bh);
  680. *bh = NULL;
  681. if (status < 0) {
  682. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  683. "upgraded before mounting with ocfs v2\n");
  684. goto bail;
  685. }
  686. /*
  687. * Now check at magic offset for 512, 1024, 2048, 4096
  688. * blocksizes. 4096 is the maximum blocksize because it is
  689. * the minimum clustersize.
  690. */
  691. status = -EINVAL;
  692. for (blksize = *sector_size;
  693. blksize <= OCFS2_MAX_BLOCKSIZE;
  694. blksize <<= 1) {
  695. tmpstat = ocfs2_get_sector(sb, bh,
  696. OCFS2_SUPER_BLOCK_BLKNO,
  697. blksize);
  698. if (tmpstat < 0) {
  699. status = tmpstat;
  700. mlog_errno(status);
  701. break;
  702. }
  703. di = (struct ocfs2_dinode *) (*bh)->b_data;
  704. memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
  705. spin_lock_init(&stats->b_lock);
  706. tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  707. if (tmpstat < 0) {
  708. brelse(*bh);
  709. *bh = NULL;
  710. }
  711. if (tmpstat != -EAGAIN) {
  712. status = tmpstat;
  713. break;
  714. }
  715. }
  716. bail:
  717. return status;
  718. }
  719. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  720. {
  721. if (ocfs2_mount_local(osb)) {
  722. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  723. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  724. "mounted device.\n");
  725. return -EINVAL;
  726. }
  727. }
  728. if (ocfs2_userspace_stack(osb)) {
  729. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  730. mlog(ML_ERROR, "Userspace stack expected, but "
  731. "o2cb heartbeat arguments passed to mount\n");
  732. return -EINVAL;
  733. }
  734. }
  735. if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  736. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  737. !ocfs2_userspace_stack(osb)) {
  738. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  739. "a read-write clustered device.\n");
  740. return -EINVAL;
  741. }
  742. }
  743. return 0;
  744. }
  745. /*
  746. * If we're using a userspace stack, mount should have passed
  747. * a name that matches the disk. If not, mount should not
  748. * have passed a stack.
  749. */
  750. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  751. struct mount_options *mopt)
  752. {
  753. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  754. mlog(ML_ERROR,
  755. "cluster stack passed to mount, but this filesystem "
  756. "does not support it\n");
  757. return -EINVAL;
  758. }
  759. if (ocfs2_userspace_stack(osb) &&
  760. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  761. OCFS2_STACK_LABEL_LEN)) {
  762. mlog(ML_ERROR,
  763. "cluster stack passed to mount (\"%s\") does not "
  764. "match the filesystem (\"%s\")\n",
  765. mopt->cluster_stack,
  766. osb->osb_cluster_stack);
  767. return -EINVAL;
  768. }
  769. return 0;
  770. }
  771. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  772. {
  773. int type;
  774. struct super_block *sb = osb->sb;
  775. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  776. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  777. int status = 0;
  778. for (type = 0; type < MAXQUOTAS; type++) {
  779. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  780. continue;
  781. if (unsuspend)
  782. status = vfs_quota_enable(
  783. sb_dqopt(sb)->files[type],
  784. type, QFMT_OCFS2,
  785. DQUOT_SUSPENDED);
  786. else
  787. status = vfs_quota_disable(sb, type,
  788. DQUOT_SUSPENDED);
  789. if (status < 0)
  790. break;
  791. }
  792. if (status < 0)
  793. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  794. "remount (error = %d).\n", status);
  795. return status;
  796. }
  797. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  798. {
  799. struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  800. struct super_block *sb = osb->sb;
  801. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  802. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  803. unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  804. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  805. int status;
  806. int type;
  807. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  808. for (type = 0; type < MAXQUOTAS; type++) {
  809. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  810. continue;
  811. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  812. osb->slot_num);
  813. if (!inode[type]) {
  814. status = -ENOENT;
  815. goto out_quota_off;
  816. }
  817. status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
  818. DQUOT_USAGE_ENABLED);
  819. if (status < 0)
  820. goto out_quota_off;
  821. }
  822. for (type = 0; type < MAXQUOTAS; type++)
  823. iput(inode[type]);
  824. return 0;
  825. out_quota_off:
  826. ocfs2_disable_quotas(osb);
  827. for (type = 0; type < MAXQUOTAS; type++)
  828. iput(inode[type]);
  829. mlog_errno(status);
  830. return status;
  831. }
  832. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  833. {
  834. int type;
  835. struct inode *inode;
  836. struct super_block *sb = osb->sb;
  837. struct ocfs2_mem_dqinfo *oinfo;
  838. /* We mostly ignore errors in this function because there's not much
  839. * we can do when we see them */
  840. for (type = 0; type < MAXQUOTAS; type++) {
  841. if (!sb_has_quota_loaded(sb, type))
  842. continue;
  843. /* Cancel periodic syncing before we grab dqonoff_mutex */
  844. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  845. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  846. inode = igrab(sb->s_dquot.files[type]);
  847. /* Turn off quotas. This will remove all dquot structures from
  848. * memory and so they will be automatically synced to global
  849. * quota files */
  850. vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
  851. DQUOT_LIMITS_ENABLED);
  852. if (!inode)
  853. continue;
  854. iput(inode);
  855. }
  856. }
  857. /* Handle quota on quotactl */
  858. static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
  859. char *path, int remount)
  860. {
  861. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  862. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  863. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  864. return -EINVAL;
  865. if (remount)
  866. return 0; /* Just ignore it has been handled in
  867. * ocfs2_remount() */
  868. return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
  869. format_id, DQUOT_LIMITS_ENABLED);
  870. }
  871. /* Handle quota off quotactl */
  872. static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
  873. {
  874. if (remount)
  875. return 0; /* Ignore now and handle later in
  876. * ocfs2_remount() */
  877. return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
  878. }
  879. static const struct quotactl_ops ocfs2_quotactl_ops = {
  880. .quota_on = ocfs2_quota_on,
  881. .quota_off = ocfs2_quota_off,
  882. .quota_sync = vfs_quota_sync,
  883. .get_info = vfs_get_dqinfo,
  884. .set_info = vfs_set_dqinfo,
  885. .get_dqblk = vfs_get_dqblk,
  886. .set_dqblk = vfs_set_dqblk,
  887. };
  888. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  889. {
  890. struct dentry *root;
  891. int status, sector_size;
  892. struct mount_options parsed_options;
  893. struct inode *inode = NULL;
  894. struct ocfs2_super *osb = NULL;
  895. struct buffer_head *bh = NULL;
  896. char nodestr[8];
  897. struct ocfs2_blockcheck_stats stats;
  898. mlog_entry("%p, %p, %i", sb, data, silent);
  899. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  900. status = -EINVAL;
  901. goto read_super_error;
  902. }
  903. /* probe for superblock */
  904. status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
  905. if (status < 0) {
  906. mlog(ML_ERROR, "superblock probe failed!\n");
  907. goto read_super_error;
  908. }
  909. status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
  910. osb = OCFS2_SB(sb);
  911. if (status < 0) {
  912. mlog_errno(status);
  913. goto read_super_error;
  914. }
  915. brelse(bh);
  916. bh = NULL;
  917. if (!ocfs2_check_set_options(sb, &parsed_options)) {
  918. status = -EINVAL;
  919. goto read_super_error;
  920. }
  921. osb->s_mount_opt = parsed_options.mount_opt;
  922. osb->s_atime_quantum = parsed_options.atime_quantum;
  923. osb->preferred_slot = parsed_options.slot;
  924. osb->osb_commit_interval = parsed_options.commit_interval;
  925. ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
  926. osb->osb_resv_level = parsed_options.resv_level;
  927. osb->osb_dir_resv_level = parsed_options.resv_level;
  928. if (parsed_options.dir_resv_level == -1)
  929. osb->osb_dir_resv_level = parsed_options.resv_level;
  930. else
  931. osb->osb_dir_resv_level = parsed_options.dir_resv_level;
  932. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  933. if (status)
  934. goto read_super_error;
  935. sb->s_magic = OCFS2_SUPER_MAGIC;
  936. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  937. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  938. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  939. * heartbeat=none */
  940. if (bdev_read_only(sb->s_bdev)) {
  941. if (!(sb->s_flags & MS_RDONLY)) {
  942. status = -EACCES;
  943. mlog(ML_ERROR, "Readonly device detected but readonly "
  944. "mount was not specified.\n");
  945. goto read_super_error;
  946. }
  947. /* You should not be able to start a local heartbeat
  948. * on a readonly device. */
  949. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  950. status = -EROFS;
  951. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  952. "device.\n");
  953. goto read_super_error;
  954. }
  955. status = ocfs2_check_journals_nolocks(osb);
  956. if (status < 0) {
  957. if (status == -EROFS)
  958. mlog(ML_ERROR, "Recovery required on readonly "
  959. "file system, but write access is "
  960. "unavailable.\n");
  961. else
  962. mlog_errno(status);
  963. goto read_super_error;
  964. }
  965. ocfs2_set_ro_flag(osb, 1);
  966. printk(KERN_NOTICE "Readonly device detected. No cluster "
  967. "services will be utilized for this mount. Recovery "
  968. "will be skipped.\n");
  969. }
  970. if (!ocfs2_is_hard_readonly(osb)) {
  971. if (sb->s_flags & MS_RDONLY)
  972. ocfs2_set_ro_flag(osb, 0);
  973. }
  974. status = ocfs2_verify_heartbeat(osb);
  975. if (status < 0) {
  976. mlog_errno(status);
  977. goto read_super_error;
  978. }
  979. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  980. ocfs2_debugfs_root);
  981. if (!osb->osb_debug_root) {
  982. status = -EINVAL;
  983. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  984. goto read_super_error;
  985. }
  986. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  987. osb->osb_debug_root,
  988. osb,
  989. &ocfs2_osb_debug_fops);
  990. if (!osb->osb_ctxt) {
  991. status = -EINVAL;
  992. mlog_errno(status);
  993. goto read_super_error;
  994. }
  995. if (ocfs2_meta_ecc(osb)) {
  996. status = ocfs2_blockcheck_stats_debugfs_install(
  997. &osb->osb_ecc_stats,
  998. osb->osb_debug_root);
  999. if (status) {
  1000. mlog(ML_ERROR,
  1001. "Unable to create blockcheck statistics "
  1002. "files\n");
  1003. goto read_super_error;
  1004. }
  1005. }
  1006. status = ocfs2_mount_volume(sb);
  1007. if (osb->root_inode)
  1008. inode = igrab(osb->root_inode);
  1009. if (status < 0)
  1010. goto read_super_error;
  1011. if (!inode) {
  1012. status = -EIO;
  1013. mlog_errno(status);
  1014. goto read_super_error;
  1015. }
  1016. root = d_alloc_root(inode);
  1017. if (!root) {
  1018. status = -ENOMEM;
  1019. mlog_errno(status);
  1020. goto read_super_error;
  1021. }
  1022. sb->s_root = root;
  1023. ocfs2_complete_mount_recovery(osb);
  1024. if (ocfs2_mount_local(osb))
  1025. snprintf(nodestr, sizeof(nodestr), "local");
  1026. else
  1027. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1028. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1029. "with %s data mode.\n",
  1030. osb->dev_str, nodestr, osb->slot_num,
  1031. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1032. "ordered");
  1033. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1034. wake_up(&osb->osb_mount_event);
  1035. /* Now we can initialize quotas because we can afford to wait
  1036. * for cluster locks recovery now. That also means that truncation
  1037. * log recovery can happen but that waits for proper quota setup */
  1038. if (!(sb->s_flags & MS_RDONLY)) {
  1039. status = ocfs2_enable_quotas(osb);
  1040. if (status < 0) {
  1041. /* We have to err-out specially here because
  1042. * s_root is already set */
  1043. mlog_errno(status);
  1044. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1045. wake_up(&osb->osb_mount_event);
  1046. mlog_exit(status);
  1047. return status;
  1048. }
  1049. }
  1050. ocfs2_complete_quota_recovery(osb);
  1051. /* Now we wake up again for processes waiting for quotas */
  1052. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1053. wake_up(&osb->osb_mount_event);
  1054. /* Start this when the mount is almost sure of being successful */
  1055. ocfs2_orphan_scan_start(osb);
  1056. mlog_exit(status);
  1057. return status;
  1058. read_super_error:
  1059. brelse(bh);
  1060. if (inode)
  1061. iput(inode);
  1062. if (osb) {
  1063. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1064. wake_up(&osb->osb_mount_event);
  1065. ocfs2_dismount_volume(sb, 1);
  1066. }
  1067. mlog_exit(status);
  1068. return status;
  1069. }
  1070. static int ocfs2_get_sb(struct file_system_type *fs_type,
  1071. int flags,
  1072. const char *dev_name,
  1073. void *data,
  1074. struct vfsmount *mnt)
  1075. {
  1076. return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
  1077. mnt);
  1078. }
  1079. static void ocfs2_kill_sb(struct super_block *sb)
  1080. {
  1081. struct ocfs2_super *osb = OCFS2_SB(sb);
  1082. /* Failed mount? */
  1083. if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
  1084. goto out;
  1085. /* Prevent further queueing of inode drop events */
  1086. spin_lock(&dentry_list_lock);
  1087. ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
  1088. spin_unlock(&dentry_list_lock);
  1089. /* Wait for work to finish and/or remove it */
  1090. cancel_work_sync(&osb->dentry_lock_work);
  1091. out:
  1092. kill_block_super(sb);
  1093. }
  1094. static struct file_system_type ocfs2_fs_type = {
  1095. .owner = THIS_MODULE,
  1096. .name = "ocfs2",
  1097. .get_sb = ocfs2_get_sb, /* is this called when we mount
  1098. * the fs? */
  1099. .kill_sb = ocfs2_kill_sb,
  1100. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1101. .next = NULL
  1102. };
  1103. static int ocfs2_check_set_options(struct super_block *sb,
  1104. struct mount_options *options)
  1105. {
  1106. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1107. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1108. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1109. mlog(ML_ERROR, "User quotas were requested, but this "
  1110. "filesystem does not have the feature enabled.\n");
  1111. return 0;
  1112. }
  1113. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1114. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1115. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1116. mlog(ML_ERROR, "Group quotas were requested, but this "
  1117. "filesystem does not have the feature enabled.\n");
  1118. return 0;
  1119. }
  1120. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1121. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1122. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1123. "feature is not enabled\n");
  1124. return 0;
  1125. }
  1126. /* No ACL setting specified? Use XATTR feature... */
  1127. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1128. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1129. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1130. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1131. else
  1132. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1133. }
  1134. return 1;
  1135. }
  1136. static int ocfs2_parse_options(struct super_block *sb,
  1137. char *options,
  1138. struct mount_options *mopt,
  1139. int is_remount)
  1140. {
  1141. int status;
  1142. char *p;
  1143. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  1144. options ? options : "(none)");
  1145. mopt->commit_interval = 0;
  1146. mopt->mount_opt = OCFS2_MOUNT_NOINTR;
  1147. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1148. mopt->slot = OCFS2_INVALID_SLOT;
  1149. mopt->localalloc_opt = -1;
  1150. mopt->cluster_stack[0] = '\0';
  1151. mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
  1152. mopt->dir_resv_level = -1;
  1153. if (!options) {
  1154. status = 1;
  1155. goto bail;
  1156. }
  1157. while ((p = strsep(&options, ",")) != NULL) {
  1158. int token, option;
  1159. substring_t args[MAX_OPT_ARGS];
  1160. if (!*p)
  1161. continue;
  1162. token = match_token(p, tokens, args);
  1163. switch (token) {
  1164. case Opt_hb_local:
  1165. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1166. break;
  1167. case Opt_hb_none:
  1168. mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
  1169. break;
  1170. case Opt_barrier:
  1171. if (match_int(&args[0], &option)) {
  1172. status = 0;
  1173. goto bail;
  1174. }
  1175. if (option)
  1176. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1177. else
  1178. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1179. break;
  1180. case Opt_intr:
  1181. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1182. break;
  1183. case Opt_nointr:
  1184. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1185. break;
  1186. case Opt_err_panic:
  1187. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1188. break;
  1189. case Opt_err_ro:
  1190. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1191. break;
  1192. case Opt_data_ordered:
  1193. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1194. break;
  1195. case Opt_data_writeback:
  1196. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1197. break;
  1198. case Opt_user_xattr:
  1199. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1200. break;
  1201. case Opt_nouser_xattr:
  1202. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1203. break;
  1204. case Opt_atime_quantum:
  1205. if (match_int(&args[0], &option)) {
  1206. status = 0;
  1207. goto bail;
  1208. }
  1209. if (option >= 0)
  1210. mopt->atime_quantum = option;
  1211. break;
  1212. case Opt_slot:
  1213. option = 0;
  1214. if (match_int(&args[0], &option)) {
  1215. status = 0;
  1216. goto bail;
  1217. }
  1218. if (option)
  1219. mopt->slot = (s16)option;
  1220. break;
  1221. case Opt_commit:
  1222. option = 0;
  1223. if (match_int(&args[0], &option)) {
  1224. status = 0;
  1225. goto bail;
  1226. }
  1227. if (option < 0)
  1228. return 0;
  1229. if (option == 0)
  1230. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1231. mopt->commit_interval = HZ * option;
  1232. break;
  1233. case Opt_localalloc:
  1234. option = 0;
  1235. if (match_int(&args[0], &option)) {
  1236. status = 0;
  1237. goto bail;
  1238. }
  1239. if (option >= 0)
  1240. mopt->localalloc_opt = option;
  1241. break;
  1242. case Opt_localflocks:
  1243. /*
  1244. * Changing this during remount could race
  1245. * flock() requests, or "unbalance" existing
  1246. * ones (e.g., a lock is taken in one mode but
  1247. * dropped in the other). If users care enough
  1248. * to flip locking modes during remount, we
  1249. * could add a "local" flag to individual
  1250. * flock structures for proper tracking of
  1251. * state.
  1252. */
  1253. if (!is_remount)
  1254. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1255. break;
  1256. case Opt_stack:
  1257. /* Check both that the option we were passed
  1258. * is of the right length and that it is a proper
  1259. * string of the right length.
  1260. */
  1261. if (((args[0].to - args[0].from) !=
  1262. OCFS2_STACK_LABEL_LEN) ||
  1263. (strnlen(args[0].from,
  1264. OCFS2_STACK_LABEL_LEN) !=
  1265. OCFS2_STACK_LABEL_LEN)) {
  1266. mlog(ML_ERROR,
  1267. "Invalid cluster_stack option\n");
  1268. status = 0;
  1269. goto bail;
  1270. }
  1271. memcpy(mopt->cluster_stack, args[0].from,
  1272. OCFS2_STACK_LABEL_LEN);
  1273. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1274. break;
  1275. case Opt_inode64:
  1276. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1277. break;
  1278. case Opt_usrquota:
  1279. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1280. break;
  1281. case Opt_grpquota:
  1282. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1283. break;
  1284. case Opt_acl:
  1285. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1286. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1287. break;
  1288. case Opt_noacl:
  1289. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1290. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1291. break;
  1292. case Opt_resv_level:
  1293. if (is_remount)
  1294. break;
  1295. if (match_int(&args[0], &option)) {
  1296. status = 0;
  1297. goto bail;
  1298. }
  1299. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1300. option < OCFS2_MAX_RESV_LEVEL)
  1301. mopt->resv_level = option;
  1302. break;
  1303. case Opt_dir_resv_level:
  1304. if (is_remount)
  1305. break;
  1306. if (match_int(&args[0], &option)) {
  1307. status = 0;
  1308. goto bail;
  1309. }
  1310. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1311. option < OCFS2_MAX_RESV_LEVEL)
  1312. mopt->dir_resv_level = option;
  1313. break;
  1314. default:
  1315. mlog(ML_ERROR,
  1316. "Unrecognized mount option \"%s\" "
  1317. "or missing value\n", p);
  1318. status = 0;
  1319. goto bail;
  1320. }
  1321. }
  1322. status = 1;
  1323. bail:
  1324. mlog_exit(status);
  1325. return status;
  1326. }
  1327. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1328. {
  1329. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  1330. unsigned long opts = osb->s_mount_opt;
  1331. unsigned int local_alloc_megs;
  1332. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1333. seq_printf(s, ",_netdev,heartbeat=local");
  1334. else
  1335. seq_printf(s, ",heartbeat=none");
  1336. if (opts & OCFS2_MOUNT_NOINTR)
  1337. seq_printf(s, ",nointr");
  1338. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1339. seq_printf(s, ",data=writeback");
  1340. else
  1341. seq_printf(s, ",data=ordered");
  1342. if (opts & OCFS2_MOUNT_BARRIER)
  1343. seq_printf(s, ",barrier=1");
  1344. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1345. seq_printf(s, ",errors=panic");
  1346. else
  1347. seq_printf(s, ",errors=remount-ro");
  1348. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1349. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1350. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  1351. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1352. if (osb->osb_commit_interval)
  1353. seq_printf(s, ",commit=%u",
  1354. (unsigned) (osb->osb_commit_interval / HZ));
  1355. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1356. if (local_alloc_megs != ocfs2_la_default_mb(osb))
  1357. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1358. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1359. seq_printf(s, ",localflocks,");
  1360. if (osb->osb_cluster_stack[0])
  1361. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  1362. osb->osb_cluster_stack);
  1363. if (opts & OCFS2_MOUNT_USRQUOTA)
  1364. seq_printf(s, ",usrquota");
  1365. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1366. seq_printf(s, ",grpquota");
  1367. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1368. seq_printf(s, ",nouser_xattr");
  1369. else
  1370. seq_printf(s, ",user_xattr");
  1371. if (opts & OCFS2_MOUNT_INODE64)
  1372. seq_printf(s, ",inode64");
  1373. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1374. seq_printf(s, ",acl");
  1375. else
  1376. seq_printf(s, ",noacl");
  1377. if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  1378. seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
  1379. if (osb->osb_dir_resv_level != osb->osb_resv_level)
  1380. seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
  1381. return 0;
  1382. }
  1383. static int __init ocfs2_init(void)
  1384. {
  1385. int status;
  1386. mlog_entry_void();
  1387. ocfs2_print_version();
  1388. status = init_ocfs2_uptodate_cache();
  1389. if (status < 0) {
  1390. mlog_errno(status);
  1391. goto leave;
  1392. }
  1393. status = ocfs2_initialize_mem_caches();
  1394. if (status < 0) {
  1395. mlog_errno(status);
  1396. goto leave;
  1397. }
  1398. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  1399. if (!ocfs2_wq) {
  1400. status = -ENOMEM;
  1401. goto leave;
  1402. }
  1403. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1404. if (!ocfs2_debugfs_root) {
  1405. status = -EFAULT;
  1406. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1407. }
  1408. status = ocfs2_quota_setup();
  1409. if (status)
  1410. goto leave;
  1411. ocfs2_set_locking_protocol();
  1412. status = register_quota_format(&ocfs2_quota_format);
  1413. leave:
  1414. if (status < 0) {
  1415. ocfs2_quota_shutdown();
  1416. ocfs2_free_mem_caches();
  1417. exit_ocfs2_uptodate_cache();
  1418. }
  1419. mlog_exit(status);
  1420. if (status >= 0) {
  1421. return register_filesystem(&ocfs2_fs_type);
  1422. } else
  1423. return -1;
  1424. }
  1425. static void __exit ocfs2_exit(void)
  1426. {
  1427. mlog_entry_void();
  1428. ocfs2_quota_shutdown();
  1429. if (ocfs2_wq) {
  1430. flush_workqueue(ocfs2_wq);
  1431. destroy_workqueue(ocfs2_wq);
  1432. }
  1433. unregister_quota_format(&ocfs2_quota_format);
  1434. debugfs_remove(ocfs2_debugfs_root);
  1435. ocfs2_free_mem_caches();
  1436. unregister_filesystem(&ocfs2_fs_type);
  1437. exit_ocfs2_uptodate_cache();
  1438. mlog_exit_void();
  1439. }
  1440. static void ocfs2_put_super(struct super_block *sb)
  1441. {
  1442. mlog_entry("(0x%p)\n", sb);
  1443. lock_kernel();
  1444. ocfs2_sync_blockdev(sb);
  1445. ocfs2_dismount_volume(sb, 0);
  1446. unlock_kernel();
  1447. mlog_exit_void();
  1448. }
  1449. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1450. {
  1451. struct ocfs2_super *osb;
  1452. u32 numbits, freebits;
  1453. int status;
  1454. struct ocfs2_dinode *bm_lock;
  1455. struct buffer_head *bh = NULL;
  1456. struct inode *inode = NULL;
  1457. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  1458. osb = OCFS2_SB(dentry->d_sb);
  1459. inode = ocfs2_get_system_file_inode(osb,
  1460. GLOBAL_BITMAP_SYSTEM_INODE,
  1461. OCFS2_INVALID_SLOT);
  1462. if (!inode) {
  1463. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1464. status = -EIO;
  1465. goto bail;
  1466. }
  1467. status = ocfs2_inode_lock(inode, &bh, 0);
  1468. if (status < 0) {
  1469. mlog_errno(status);
  1470. goto bail;
  1471. }
  1472. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1473. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1474. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1475. buf->f_type = OCFS2_SUPER_MAGIC;
  1476. buf->f_bsize = dentry->d_sb->s_blocksize;
  1477. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1478. buf->f_blocks = ((sector_t) numbits) *
  1479. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1480. buf->f_bfree = ((sector_t) freebits) *
  1481. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1482. buf->f_bavail = buf->f_bfree;
  1483. buf->f_files = numbits;
  1484. buf->f_ffree = freebits;
  1485. buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  1486. & 0xFFFFFFFFUL;
  1487. buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  1488. OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
  1489. brelse(bh);
  1490. ocfs2_inode_unlock(inode, 0);
  1491. status = 0;
  1492. bail:
  1493. if (inode)
  1494. iput(inode);
  1495. mlog_exit(status);
  1496. return status;
  1497. }
  1498. static void ocfs2_inode_init_once(void *data)
  1499. {
  1500. struct ocfs2_inode_info *oi = data;
  1501. oi->ip_flags = 0;
  1502. oi->ip_open_count = 0;
  1503. spin_lock_init(&oi->ip_lock);
  1504. ocfs2_extent_map_init(&oi->vfs_inode);
  1505. INIT_LIST_HEAD(&oi->ip_io_markers);
  1506. oi->ip_dir_start_lookup = 0;
  1507. init_rwsem(&oi->ip_alloc_sem);
  1508. init_rwsem(&oi->ip_xattr_sem);
  1509. mutex_init(&oi->ip_io_mutex);
  1510. oi->ip_blkno = 0ULL;
  1511. oi->ip_clusters = 0;
  1512. ocfs2_resv_init_once(&oi->ip_la_data_resv);
  1513. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1514. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1515. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1516. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1517. &ocfs2_inode_caching_ops);
  1518. inode_init_once(&oi->vfs_inode);
  1519. }
  1520. static int ocfs2_initialize_mem_caches(void)
  1521. {
  1522. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1523. sizeof(struct ocfs2_inode_info),
  1524. 0,
  1525. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1526. SLAB_MEM_SPREAD),
  1527. ocfs2_inode_init_once);
  1528. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1529. sizeof(struct ocfs2_dquot),
  1530. 0,
  1531. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1532. SLAB_MEM_SPREAD),
  1533. NULL);
  1534. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1535. sizeof(struct ocfs2_quota_chunk),
  1536. 0,
  1537. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1538. NULL);
  1539. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1540. !ocfs2_qf_chunk_cachep) {
  1541. if (ocfs2_inode_cachep)
  1542. kmem_cache_destroy(ocfs2_inode_cachep);
  1543. if (ocfs2_dquot_cachep)
  1544. kmem_cache_destroy(ocfs2_dquot_cachep);
  1545. if (ocfs2_qf_chunk_cachep)
  1546. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1547. return -ENOMEM;
  1548. }
  1549. return 0;
  1550. }
  1551. static void ocfs2_free_mem_caches(void)
  1552. {
  1553. if (ocfs2_inode_cachep)
  1554. kmem_cache_destroy(ocfs2_inode_cachep);
  1555. ocfs2_inode_cachep = NULL;
  1556. if (ocfs2_dquot_cachep)
  1557. kmem_cache_destroy(ocfs2_dquot_cachep);
  1558. ocfs2_dquot_cachep = NULL;
  1559. if (ocfs2_qf_chunk_cachep)
  1560. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1561. ocfs2_qf_chunk_cachep = NULL;
  1562. }
  1563. static int ocfs2_get_sector(struct super_block *sb,
  1564. struct buffer_head **bh,
  1565. int block,
  1566. int sect_size)
  1567. {
  1568. if (!sb_set_blocksize(sb, sect_size)) {
  1569. mlog(ML_ERROR, "unable to set blocksize\n");
  1570. return -EIO;
  1571. }
  1572. *bh = sb_getblk(sb, block);
  1573. if (!*bh) {
  1574. mlog_errno(-EIO);
  1575. return -EIO;
  1576. }
  1577. lock_buffer(*bh);
  1578. if (!buffer_dirty(*bh))
  1579. clear_buffer_uptodate(*bh);
  1580. unlock_buffer(*bh);
  1581. ll_rw_block(READ, 1, bh);
  1582. wait_on_buffer(*bh);
  1583. if (!buffer_uptodate(*bh)) {
  1584. mlog_errno(-EIO);
  1585. brelse(*bh);
  1586. *bh = NULL;
  1587. return -EIO;
  1588. }
  1589. return 0;
  1590. }
  1591. static int ocfs2_mount_volume(struct super_block *sb)
  1592. {
  1593. int status = 0;
  1594. int unlock_super = 0;
  1595. struct ocfs2_super *osb = OCFS2_SB(sb);
  1596. mlog_entry_void();
  1597. if (ocfs2_is_hard_readonly(osb))
  1598. goto leave;
  1599. status = ocfs2_dlm_init(osb);
  1600. if (status < 0) {
  1601. mlog_errno(status);
  1602. goto leave;
  1603. }
  1604. status = ocfs2_super_lock(osb, 1);
  1605. if (status < 0) {
  1606. mlog_errno(status);
  1607. goto leave;
  1608. }
  1609. unlock_super = 1;
  1610. /* This will load up the node map and add ourselves to it. */
  1611. status = ocfs2_find_slot(osb);
  1612. if (status < 0) {
  1613. mlog_errno(status);
  1614. goto leave;
  1615. }
  1616. /* load all node-local system inodes */
  1617. status = ocfs2_init_local_system_inodes(osb);
  1618. if (status < 0) {
  1619. mlog_errno(status);
  1620. goto leave;
  1621. }
  1622. status = ocfs2_check_volume(osb);
  1623. if (status < 0) {
  1624. mlog_errno(status);
  1625. goto leave;
  1626. }
  1627. status = ocfs2_truncate_log_init(osb);
  1628. if (status < 0)
  1629. mlog_errno(status);
  1630. leave:
  1631. if (unlock_super)
  1632. ocfs2_super_unlock(osb, 1);
  1633. mlog_exit(status);
  1634. return status;
  1635. }
  1636. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1637. {
  1638. int tmp, hangup_needed = 0;
  1639. struct ocfs2_super *osb = NULL;
  1640. char nodestr[8];
  1641. mlog_entry("(0x%p)\n", sb);
  1642. BUG_ON(!sb);
  1643. osb = OCFS2_SB(sb);
  1644. BUG_ON(!osb);
  1645. debugfs_remove(osb->osb_ctxt);
  1646. /*
  1647. * Flush inode dropping work queue so that deletes are
  1648. * performed while the filesystem is still working
  1649. */
  1650. ocfs2_drop_all_dl_inodes(osb);
  1651. /* Orphan scan should be stopped as early as possible */
  1652. ocfs2_orphan_scan_stop(osb);
  1653. ocfs2_disable_quotas(osb);
  1654. ocfs2_shutdown_local_alloc(osb);
  1655. ocfs2_truncate_log_shutdown(osb);
  1656. /* This will disable recovery and flush any recovery work. */
  1657. ocfs2_recovery_exit(osb);
  1658. ocfs2_journal_shutdown(osb);
  1659. ocfs2_sync_blockdev(sb);
  1660. ocfs2_purge_refcount_trees(osb);
  1661. /* No cluster connection means we've failed during mount, so skip
  1662. * all the steps which depended on that to complete. */
  1663. if (osb->cconn) {
  1664. tmp = ocfs2_super_lock(osb, 1);
  1665. if (tmp < 0) {
  1666. mlog_errno(tmp);
  1667. return;
  1668. }
  1669. }
  1670. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1671. ocfs2_put_slot(osb);
  1672. if (osb->cconn)
  1673. ocfs2_super_unlock(osb, 1);
  1674. ocfs2_release_system_inodes(osb);
  1675. /*
  1676. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1677. * up heartbeat. If we're a local mount, there is no heartbeat.
  1678. * If we failed before we got a uuid_str yet, we can't stop
  1679. * heartbeat. Otherwise, do it.
  1680. */
  1681. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1682. hangup_needed = 1;
  1683. if (osb->cconn)
  1684. ocfs2_dlm_shutdown(osb, hangup_needed);
  1685. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1686. debugfs_remove(osb->osb_debug_root);
  1687. if (hangup_needed)
  1688. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1689. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1690. if (ocfs2_mount_local(osb))
  1691. snprintf(nodestr, sizeof(nodestr), "local");
  1692. else
  1693. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1694. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1695. osb->dev_str, nodestr);
  1696. ocfs2_delete_osb(osb);
  1697. kfree(osb);
  1698. sb->s_dev = 0;
  1699. sb->s_fs_info = NULL;
  1700. }
  1701. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1702. unsigned uuid_bytes)
  1703. {
  1704. int i, ret;
  1705. char *ptr;
  1706. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1707. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1708. if (osb->uuid_str == NULL)
  1709. return -ENOMEM;
  1710. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1711. /* print with null */
  1712. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1713. if (ret != 2) /* drop super cleans up */
  1714. return -EINVAL;
  1715. /* then only advance past the last char */
  1716. ptr += 2;
  1717. }
  1718. return 0;
  1719. }
  1720. static int ocfs2_initialize_super(struct super_block *sb,
  1721. struct buffer_head *bh,
  1722. int sector_size,
  1723. struct ocfs2_blockcheck_stats *stats)
  1724. {
  1725. int status;
  1726. int i, cbits, bbits;
  1727. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1728. struct inode *inode = NULL;
  1729. struct ocfs2_journal *journal;
  1730. __le32 uuid_net_key;
  1731. struct ocfs2_super *osb;
  1732. mlog_entry_void();
  1733. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1734. if (!osb) {
  1735. status = -ENOMEM;
  1736. mlog_errno(status);
  1737. goto bail;
  1738. }
  1739. sb->s_fs_info = osb;
  1740. sb->s_op = &ocfs2_sops;
  1741. sb->s_export_op = &ocfs2_export_ops;
  1742. sb->s_qcop = &ocfs2_quotactl_ops;
  1743. sb->dq_op = &ocfs2_quota_operations;
  1744. sb->s_xattr = ocfs2_xattr_handlers;
  1745. sb->s_time_gran = 1;
  1746. sb->s_flags |= MS_NOATIME;
  1747. /* this is needed to support O_LARGEFILE */
  1748. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1749. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1750. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1751. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1752. for (i = 0; i < 3; i++)
  1753. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1754. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1755. osb->sb = sb;
  1756. /* Save off for ocfs2_rw_direct */
  1757. osb->s_sectsize_bits = blksize_bits(sector_size);
  1758. BUG_ON(!osb->s_sectsize_bits);
  1759. spin_lock_init(&osb->dc_task_lock);
  1760. init_waitqueue_head(&osb->dc_event);
  1761. osb->dc_work_sequence = 0;
  1762. osb->dc_wake_sequence = 0;
  1763. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1764. osb->blocked_lock_count = 0;
  1765. spin_lock_init(&osb->osb_lock);
  1766. spin_lock_init(&osb->osb_xattr_lock);
  1767. ocfs2_init_steal_slots(osb);
  1768. atomic_set(&osb->alloc_stats.moves, 0);
  1769. atomic_set(&osb->alloc_stats.local_data, 0);
  1770. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1771. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1772. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1773. /* Copy the blockcheck stats from the superblock probe */
  1774. osb->osb_ecc_stats = *stats;
  1775. ocfs2_init_node_maps(osb);
  1776. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1777. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1778. ocfs2_orphan_scan_init(osb);
  1779. status = ocfs2_recovery_init(osb);
  1780. if (status) {
  1781. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1782. mlog_errno(status);
  1783. goto bail;
  1784. }
  1785. init_waitqueue_head(&osb->checkpoint_event);
  1786. atomic_set(&osb->needs_checkpoint, 0);
  1787. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1788. osb->slot_num = OCFS2_INVALID_SLOT;
  1789. osb->s_xattr_inline_size = le16_to_cpu(
  1790. di->id2.i_super.s_xattr_inline_size);
  1791. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1792. osb->local_alloc_bh = NULL;
  1793. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1794. init_waitqueue_head(&osb->osb_mount_event);
  1795. status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  1796. if (status) {
  1797. mlog_errno(status);
  1798. goto bail;
  1799. }
  1800. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1801. if (!osb->vol_label) {
  1802. mlog(ML_ERROR, "unable to alloc vol label\n");
  1803. status = -ENOMEM;
  1804. goto bail;
  1805. }
  1806. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1807. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1808. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1809. osb->max_slots);
  1810. status = -EINVAL;
  1811. goto bail;
  1812. }
  1813. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1814. osb->slot_recovery_generations =
  1815. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1816. GFP_KERNEL);
  1817. if (!osb->slot_recovery_generations) {
  1818. status = -ENOMEM;
  1819. mlog_errno(status);
  1820. goto bail;
  1821. }
  1822. init_waitqueue_head(&osb->osb_wipe_event);
  1823. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1824. sizeof(*osb->osb_orphan_wipes),
  1825. GFP_KERNEL);
  1826. if (!osb->osb_orphan_wipes) {
  1827. status = -ENOMEM;
  1828. mlog_errno(status);
  1829. goto bail;
  1830. }
  1831. osb->osb_rf_lock_tree = RB_ROOT;
  1832. osb->s_feature_compat =
  1833. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1834. osb->s_feature_ro_compat =
  1835. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1836. osb->s_feature_incompat =
  1837. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1838. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1839. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1840. "optional features (%x).\n", i);
  1841. status = -EINVAL;
  1842. goto bail;
  1843. }
  1844. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1845. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1846. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1847. "unsupported optional features (%x).\n", i);
  1848. status = -EINVAL;
  1849. goto bail;
  1850. }
  1851. if (ocfs2_userspace_stack(osb)) {
  1852. memcpy(osb->osb_cluster_stack,
  1853. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1854. OCFS2_STACK_LABEL_LEN);
  1855. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1856. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1857. mlog(ML_ERROR,
  1858. "couldn't mount because of an invalid "
  1859. "cluster stack label (%s) \n",
  1860. osb->osb_cluster_stack);
  1861. status = -EINVAL;
  1862. goto bail;
  1863. }
  1864. } else {
  1865. /* The empty string is identical with classic tools that
  1866. * don't know about s_cluster_info. */
  1867. osb->osb_cluster_stack[0] = '\0';
  1868. }
  1869. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1870. /* FIXME
  1871. * This should be done in ocfs2_journal_init(), but unknown
  1872. * ordering issues will cause the filesystem to crash.
  1873. * If anyone wants to figure out what part of the code
  1874. * refers to osb->journal before ocfs2_journal_init() is run,
  1875. * be my guest.
  1876. */
  1877. /* initialize our journal structure */
  1878. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1879. if (!journal) {
  1880. mlog(ML_ERROR, "unable to alloc journal\n");
  1881. status = -ENOMEM;
  1882. goto bail;
  1883. }
  1884. osb->journal = journal;
  1885. journal->j_osb = osb;
  1886. atomic_set(&journal->j_num_trans, 0);
  1887. init_rwsem(&journal->j_trans_barrier);
  1888. init_waitqueue_head(&journal->j_checkpointed);
  1889. spin_lock_init(&journal->j_lock);
  1890. journal->j_trans_id = (unsigned long) 1;
  1891. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1892. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1893. journal->j_state = OCFS2_JOURNAL_FREE;
  1894. INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  1895. osb->dentry_lock_list = NULL;
  1896. /* get some pseudo constants for clustersize bits */
  1897. osb->s_clustersize_bits =
  1898. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1899. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1900. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1901. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1902. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1903. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1904. osb->s_clustersize);
  1905. status = -EINVAL;
  1906. goto bail;
  1907. }
  1908. if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
  1909. > (u32)~0UL) {
  1910. mlog(ML_ERROR, "Volume might try to write to blocks beyond "
  1911. "what jbd can address in 32 bits.\n");
  1912. status = -EINVAL;
  1913. goto bail;
  1914. }
  1915. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1916. sizeof(di->id2.i_super.s_uuid))) {
  1917. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1918. status = -ENOMEM;
  1919. goto bail;
  1920. }
  1921. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  1922. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  1923. osb->vol_label[63] = '\0';
  1924. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1925. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1926. osb->first_cluster_group_blkno =
  1927. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1928. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1929. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1930. mlog(0, "vol_label: %s\n", osb->vol_label);
  1931. mlog(0, "uuid: %s\n", osb->uuid_str);
  1932. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  1933. (unsigned long long)osb->root_blkno,
  1934. (unsigned long long)osb->system_dir_blkno);
  1935. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1936. if (!osb->osb_dlm_debug) {
  1937. status = -ENOMEM;
  1938. mlog_errno(status);
  1939. goto bail;
  1940. }
  1941. atomic_set(&osb->vol_state, VOLUME_INIT);
  1942. /* load root, system_dir, and all global system inodes */
  1943. status = ocfs2_init_global_system_inodes(osb);
  1944. if (status < 0) {
  1945. mlog_errno(status);
  1946. goto bail;
  1947. }
  1948. /*
  1949. * global bitmap
  1950. */
  1951. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  1952. OCFS2_INVALID_SLOT);
  1953. if (!inode) {
  1954. status = -EINVAL;
  1955. mlog_errno(status);
  1956. goto bail;
  1957. }
  1958. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  1959. osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
  1960. iput(inode);
  1961. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  1962. osb->s_feature_incompat) * 8;
  1963. status = ocfs2_init_slot_info(osb);
  1964. if (status < 0) {
  1965. mlog_errno(status);
  1966. goto bail;
  1967. }
  1968. bail:
  1969. mlog_exit(status);
  1970. return status;
  1971. }
  1972. /*
  1973. * will return: -EAGAIN if it is ok to keep searching for superblocks
  1974. * -EINVAL if there is a bad superblock
  1975. * 0 on success
  1976. */
  1977. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  1978. struct buffer_head *bh,
  1979. u32 blksz,
  1980. struct ocfs2_blockcheck_stats *stats)
  1981. {
  1982. int status = -EAGAIN;
  1983. mlog_entry_void();
  1984. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  1985. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  1986. /* We have to do a raw check of the feature here */
  1987. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  1988. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  1989. status = ocfs2_block_check_validate(bh->b_data,
  1990. bh->b_size,
  1991. &di->i_check,
  1992. stats);
  1993. if (status)
  1994. goto out;
  1995. }
  1996. status = -EINVAL;
  1997. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  1998. mlog(ML_ERROR, "found superblock with incorrect block "
  1999. "size: found %u, should be %u\n",
  2000. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  2001. blksz);
  2002. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  2003. OCFS2_MAJOR_REV_LEVEL ||
  2004. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  2005. OCFS2_MINOR_REV_LEVEL) {
  2006. mlog(ML_ERROR, "found superblock with bad version: "
  2007. "found %u.%u, should be %u.%u\n",
  2008. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  2009. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  2010. OCFS2_MAJOR_REV_LEVEL,
  2011. OCFS2_MINOR_REV_LEVEL);
  2012. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  2013. mlog(ML_ERROR, "bad block number on superblock: "
  2014. "found %llu, should be %llu\n",
  2015. (unsigned long long)le64_to_cpu(di->i_blkno),
  2016. (unsigned long long)bh->b_blocknr);
  2017. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  2018. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  2019. mlog(ML_ERROR, "bad cluster size found: %u\n",
  2020. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  2021. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  2022. mlog(ML_ERROR, "bad root_blkno: 0\n");
  2023. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  2024. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  2025. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  2026. mlog(ML_ERROR,
  2027. "Superblock slots found greater than file system "
  2028. "maximum: found %u, max %u\n",
  2029. le16_to_cpu(di->id2.i_super.s_max_slots),
  2030. OCFS2_MAX_SLOTS);
  2031. } else {
  2032. /* found it! */
  2033. status = 0;
  2034. }
  2035. }
  2036. out:
  2037. mlog_exit(status);
  2038. return status;
  2039. }
  2040. static int ocfs2_check_volume(struct ocfs2_super *osb)
  2041. {
  2042. int status;
  2043. int dirty;
  2044. int local;
  2045. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  2046. * recover
  2047. * ourselves. */
  2048. mlog_entry_void();
  2049. /* Init our journal object. */
  2050. status = ocfs2_journal_init(osb->journal, &dirty);
  2051. if (status < 0) {
  2052. mlog(ML_ERROR, "Could not initialize journal!\n");
  2053. goto finally;
  2054. }
  2055. /* If the journal was unmounted cleanly then we don't want to
  2056. * recover anything. Otherwise, journal_load will do that
  2057. * dirty work for us :) */
  2058. if (!dirty) {
  2059. status = ocfs2_journal_wipe(osb->journal, 0);
  2060. if (status < 0) {
  2061. mlog_errno(status);
  2062. goto finally;
  2063. }
  2064. } else {
  2065. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  2066. "recovering volume.\n");
  2067. }
  2068. local = ocfs2_mount_local(osb);
  2069. /* will play back anything left in the journal. */
  2070. status = ocfs2_journal_load(osb->journal, local, dirty);
  2071. if (status < 0) {
  2072. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2073. goto finally;
  2074. }
  2075. if (dirty) {
  2076. /* recover my local alloc if we didn't unmount cleanly. */
  2077. status = ocfs2_begin_local_alloc_recovery(osb,
  2078. osb->slot_num,
  2079. &local_alloc);
  2080. if (status < 0) {
  2081. mlog_errno(status);
  2082. goto finally;
  2083. }
  2084. /* we complete the recovery process after we've marked
  2085. * ourselves as mounted. */
  2086. }
  2087. mlog(0, "Journal loaded.\n");
  2088. status = ocfs2_load_local_alloc(osb);
  2089. if (status < 0) {
  2090. mlog_errno(status);
  2091. goto finally;
  2092. }
  2093. if (dirty) {
  2094. /* Recovery will be completed after we've mounted the
  2095. * rest of the volume. */
  2096. osb->dirty = 1;
  2097. osb->local_alloc_copy = local_alloc;
  2098. local_alloc = NULL;
  2099. }
  2100. /* go through each journal, trylock it and if you get the
  2101. * lock, and it's marked as dirty, set the bit in the recover
  2102. * map and launch a recovery thread for it. */
  2103. status = ocfs2_mark_dead_nodes(osb);
  2104. if (status < 0) {
  2105. mlog_errno(status);
  2106. goto finally;
  2107. }
  2108. status = ocfs2_compute_replay_slots(osb);
  2109. if (status < 0)
  2110. mlog_errno(status);
  2111. finally:
  2112. if (local_alloc)
  2113. kfree(local_alloc);
  2114. mlog_exit(status);
  2115. return status;
  2116. }
  2117. /*
  2118. * The routine gets called from dismount or close whenever a dismount on
  2119. * volume is requested and the osb open count becomes 1.
  2120. * It will remove the osb from the global list and also free up all the
  2121. * initialized resources and fileobject.
  2122. */
  2123. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2124. {
  2125. mlog_entry_void();
  2126. /* This function assumes that the caller has the main osb resource */
  2127. ocfs2_free_slot_info(osb);
  2128. kfree(osb->osb_orphan_wipes);
  2129. kfree(osb->slot_recovery_generations);
  2130. /* FIXME
  2131. * This belongs in journal shutdown, but because we have to
  2132. * allocate osb->journal at the start of ocfs2_initalize_osb(),
  2133. * we free it here.
  2134. */
  2135. kfree(osb->journal);
  2136. if (osb->local_alloc_copy)
  2137. kfree(osb->local_alloc_copy);
  2138. kfree(osb->uuid_str);
  2139. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2140. memset(osb, 0, sizeof(struct ocfs2_super));
  2141. mlog_exit_void();
  2142. }
  2143. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  2144. * panic(). We do not support continue-on-error operation. */
  2145. static void ocfs2_handle_error(struct super_block *sb)
  2146. {
  2147. struct ocfs2_super *osb = OCFS2_SB(sb);
  2148. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  2149. panic("OCFS2: (device %s): panic forced after error\n",
  2150. sb->s_id);
  2151. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2152. if (sb->s_flags & MS_RDONLY &&
  2153. (ocfs2_is_soft_readonly(osb) ||
  2154. ocfs2_is_hard_readonly(osb)))
  2155. return;
  2156. printk(KERN_CRIT "File system is now read-only due to the potential "
  2157. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  2158. "system is unmounted.\n");
  2159. sb->s_flags |= MS_RDONLY;
  2160. ocfs2_set_ro_flag(osb, 0);
  2161. }
  2162. static char error_buf[1024];
  2163. void __ocfs2_error(struct super_block *sb,
  2164. const char *function,
  2165. const char *fmt, ...)
  2166. {
  2167. va_list args;
  2168. va_start(args, fmt);
  2169. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2170. va_end(args);
  2171. /* Not using mlog here because we want to show the actual
  2172. * function the error came from. */
  2173. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  2174. sb->s_id, function, error_buf);
  2175. ocfs2_handle_error(sb);
  2176. }
  2177. /* Handle critical errors. This is intentionally more drastic than
  2178. * ocfs2_handle_error, so we only use for things like journal errors,
  2179. * etc. */
  2180. void __ocfs2_abort(struct super_block* sb,
  2181. const char *function,
  2182. const char *fmt, ...)
  2183. {
  2184. va_list args;
  2185. va_start(args, fmt);
  2186. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2187. va_end(args);
  2188. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  2189. sb->s_id, function, error_buf);
  2190. /* We don't have the cluster support yet to go straight to
  2191. * hard readonly in here. Until then, we want to keep
  2192. * ocfs2_abort() so that we can at least mark critical
  2193. * errors.
  2194. *
  2195. * TODO: This should abort the journal and alert other nodes
  2196. * that our slot needs recovery. */
  2197. /* Force a panic(). This stinks, but it's better than letting
  2198. * things continue without having a proper hard readonly
  2199. * here. */
  2200. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2201. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2202. ocfs2_handle_error(sb);
  2203. }
  2204. /*
  2205. * Void signal blockers, because in-kernel sigprocmask() only fails
  2206. * when SIG_* is wrong.
  2207. */
  2208. void ocfs2_block_signals(sigset_t *oldset)
  2209. {
  2210. int rc;
  2211. sigset_t blocked;
  2212. sigfillset(&blocked);
  2213. rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  2214. BUG_ON(rc);
  2215. }
  2216. void ocfs2_unblock_signals(sigset_t *oldset)
  2217. {
  2218. int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  2219. BUG_ON(rc);
  2220. }
  2221. module_init(ocfs2_init);
  2222. module_exit(ocfs2_exit);