super.c 69 KB

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