super.c 66 KB

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