super.c 63 KB

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