super.c 69 KB

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