super.c 69 KB

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