super.c 69 KB

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