Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/ufs/ufs_filio.c
+++ new/usr/src/uts/common/fs/ufs/ufs_filio.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #include <sys/types.h>
26 26 #include <sys/t_lock.h>
27 27 #include <sys/param.h>
28 28 #include <sys/time.h>
29 29 #include <sys/systm.h>
30 30 #include <sys/sysmacros.h>
31 31 #include <sys/resource.h>
32 32 #include <sys/signal.h>
33 33 #include <sys/cred.h>
34 34 #include <sys/user.h>
35 35 #include <sys/buf.h>
36 36 #include <sys/vfs.h>
37 37 #include <sys/vnode.h>
38 38 #include <sys/proc.h>
39 39 #include <sys/disp.h>
40 40 #include <sys/file.h>
41 41 #include <sys/fcntl.h>
42 42 #include <sys/flock.h>
43 43 #include <sys/atomic.h>
44 44 #include <sys/kmem.h>
45 45 #include <sys/uio.h>
46 46 #include <sys/conf.h>
47 47 #include <sys/mman.h>
48 48 #include <sys/pathname.h>
49 49 #include <sys/debug.h>
50 50 #include <sys/vmsystm.h>
51 51 #include <sys/cmn_err.h>
52 52 #include <sys/filio.h>
53 53 #include <sys/dnlc.h>
54 54
55 55 #include <sys/fs/ufs_filio.h>
56 56 #include <sys/fs/ufs_lockfs.h>
57 57 #include <sys/fs/ufs_fs.h>
58 58 #include <sys/fs/ufs_inode.h>
59 59 #include <sys/fs/ufs_fsdir.h>
60 60 #include <sys/fs/ufs_quota.h>
61 61 #include <sys/fs/ufs_trans.h>
62 62 #include <sys/fs/ufs_log.h>
63 63 #include <sys/dirent.h> /* must be AFTER <sys/fs/fsdir.h>! */
64 64 #include <sys/errno.h>
65 65 #include <sys/sysinfo.h>
66 66
67 67 #include <vm/hat.h>
68 68 #include <vm/page.h>
69 69 #include <vm/pvn.h>
70 70 #include <vm/as.h>
71 71 #include <vm/seg.h>
72 72 #include <vm/seg_map.h>
73 73 #include <vm/seg_vn.h>
74 74 #include <vm/rm.h>
75 75 #include <sys/swap.h>
76 76 #include <sys/model.h>
77 77 #include <sys/policy.h>
78 78
79 79 #include "fs/fs_subr.h"
80 80
81 81 /*
82 82 * ufs_fioio is the ufs equivalent of NFS_CNVT and is tailored to
83 83 * metamucil's needs. It may change at any time.
84 84 */
85 85 /* ARGSUSED */
86 86 int
87 87 ufs_fioio(
88 88 struct vnode *vp, /* any file on the fs */
89 89 struct fioio *fiou, /* fioio struct in userland */
90 90 int flag, /* flag from VOP_IOCTL() */
91 91 struct cred *cr) /* credentials from ufs_ioctl */
92 92 {
93 93 int error = 0;
94 94 struct vnode *vpio = NULL; /* vnode for inode open */
95 95 struct inode *ipio = NULL; /* inode for inode open */
96 96 struct file *fpio = NULL; /* file for inode open */
97 97 struct inode *ip; /* inode for file system */
98 98 struct fs *fs; /* fs for file system */
99 99 STRUCT_DECL(fioio, fio); /* copy of user's fioio struct */
100 100
101 101 /*
102 102 * must be privileged
103 103 */
104 104 if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
105 105 return (EPERM);
106 106
107 107 STRUCT_INIT(fio, flag & DATAMODEL_MASK);
108 108
109 109 /*
110 110 * get user's copy of fioio struct
111 111 */
112 112 if (copyin(fiou, STRUCT_BUF(fio), STRUCT_SIZE(fio)))
113 113 return (EFAULT);
114 114
115 115 ip = VTOI(vp);
116 116 fs = ip->i_fs;
117 117
118 118 /*
119 119 * check the inode number against the fs's inode number bounds
120 120 */
121 121 if (STRUCT_FGET(fio, fio_ino) < UFSROOTINO)
122 122 return (ESRCH);
123 123 if (STRUCT_FGET(fio, fio_ino) >= fs->fs_ncg * fs->fs_ipg)
124 124 return (ESRCH);
125 125
126 126 rw_enter(&ip->i_ufsvfs->vfs_dqrwlock, RW_READER);
127 127
128 128 /*
129 129 * get the inode
130 130 */
131 131 error = ufs_iget(ip->i_vfs, STRUCT_FGET(fio, fio_ino), &ipio, cr);
132 132
133 133 rw_exit(&ip->i_ufsvfs->vfs_dqrwlock);
134 134
135 135 if (error)
136 136 return (error);
137 137
138 138 /*
139 139 * check the generation number
140 140 */
141 141 rw_enter(&ipio->i_contents, RW_READER);
142 142 if (ipio->i_gen != STRUCT_FGET(fio, fio_gen)) {
143 143 error = ESTALE;
144 144 rw_exit(&ipio->i_contents);
145 145 goto errout;
146 146 }
147 147
148 148 /*
149 149 * check if the inode is free
150 150 */
151 151 if (ipio->i_mode == 0) {
152 152 error = ENOENT;
153 153 rw_exit(&ipio->i_contents);
154 154 goto errout;
155 155 }
156 156 rw_exit(&ipio->i_contents);
157 157
158 158 /*
159 159 * Adapted from copen: get a file struct
160 160 * Large Files: We open this file descriptor with FOFFMAX flag
161 161 * set so that it will be like a large file open.
162 162 */
163 163 if (falloc(NULL, (FREAD|FOFFMAX), &fpio, STRUCT_FADDR(fio, fio_fd)))
164 164 goto errout;
165 165
166 166 /*
167 167 * Adapted from vn_open: check access and then open the file
168 168 */
169 169 vpio = ITOV(ipio);
170 170 if (error = VOP_ACCESS(vpio, VREAD, 0, cr, NULL))
171 171 goto errout;
172 172
173 173 if (error = VOP_OPEN(&vpio, FREAD, cr, NULL))
174 174 goto errout;
175 175
176 176 /*
177 177 * Adapted from copen: initialize the file struct
178 178 */
179 179 fpio->f_vnode = vpio;
180 180
181 181 /*
182 182 * return the fd
183 183 */
184 184 if (copyout(STRUCT_BUF(fio), fiou, STRUCT_SIZE(fio))) {
185 185 error = EFAULT;
186 186 goto errout;
187 187 }
188 188 setf(STRUCT_FGET(fio, fio_fd), fpio);
189 189 mutex_exit(&fpio->f_tlock);
190 190 return (0);
191 191 errout:
192 192 /*
193 193 * free the file struct and fd
194 194 */
195 195 if (fpio) {
196 196 setf(STRUCT_FGET(fio, fio_fd), NULL);
197 197 unfalloc(fpio);
198 198 }
199 199
200 200 /*
201 201 * release the hold on the inode
202 202 */
203 203 if (ipio)
204 204 VN_RELE(ITOV(ipio));
205 205 return (error);
206 206 }
207 207
208 208 /*
209 209 * ufs_fiosatime
210 210 * set access time w/o altering change time. This ioctl is tailored
211 211 * to metamucil's needs and may change at any time.
212 212 */
213 213 int
214 214 ufs_fiosatime(
215 215 struct vnode *vp, /* file's vnode */
216 216 struct timeval *tvu, /* struct timeval in userland */
217 217 int flag, /* flag from VOP_IOCTL() */
218 218 struct cred *cr) /* credentials from ufs_ioctl */
219 219 {
220 220 struct inode *ip; /* inode for vp */
221 221 struct timeval32 tv; /* copy of user's timeval */
222 222 int now = 0;
223 223
224 224 /*
225 225 * must have sufficient privileges
226 226 */
227 227 if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
228 228 return (EPERM);
229 229
230 230 /*
231 231 * get user's copy of timeval struct and check values
232 232 * if input is NULL, will set time to now
233 233 */
234 234 if (tvu == NULL) {
235 235 now = 1;
236 236 } else {
237 237 if ((flag & DATAMODEL_MASK) == DATAMODEL_ILP32) {
238 238 if (copyin(tvu, &tv, sizeof (tv)))
239 239 return (EFAULT);
240 240 } else {
241 241 struct timeval tv64;
242 242
243 243 if (copyin(tvu, &tv64, sizeof (tv64)))
244 244 return (EFAULT);
245 245 if (TIMEVAL_OVERFLOW(&tv64))
246 246 return (EOVERFLOW);
247 247 TIMEVAL_TO_TIMEVAL32(&tv, &tv64);
248 248 }
249 249
250 250 if (tv.tv_usec < 0 || tv.tv_usec >= 1000000)
251 251 return (EINVAL);
252 252 }
253 253
254 254 /*
255 255 * update access time
256 256 */
257 257 ip = VTOI(vp);
258 258 rw_enter(&ip->i_contents, RW_WRITER);
259 259 ITIMES_NOLOCK(ip);
260 260 if (now) {
261 261 mutex_enter(&ufs_iuniqtime_lock);
262 262 ip->i_atime = iuniqtime;
263 263 mutex_exit(&ufs_iuniqtime_lock);
264 264 } else {
265 265 ip->i_atime = tv;
266 266 }
267 267 ip->i_flag |= IMODACC;
268 268 rw_exit(&ip->i_contents);
269 269
270 270 return (0);
271 271 }
272 272
273 273 /*
274 274 * ufs_fiogdio
275 275 * Get delayed-io state. This ioctl is tailored
276 276 * to metamucil's needs and may change at any time.
277 277 */
278 278 /* ARGSUSED */
279 279 int
280 280 ufs_fiogdio(
281 281 struct vnode *vp, /* file's vnode */
282 282 uint_t *diop, /* dio state returned here */
283 283 int flag, /* flag from ufs_ioctl */
284 284 struct cred *cr) /* credentials from ufs_ioctl */
285 285 {
286 286 struct ufsvfs *ufsvfsp = VTOI(vp)->i_ufsvfs;
287 287
288 288 /*
289 289 * forcibly unmounted
290 290 */
291 291 if (ufsvfsp == NULL)
292 292 return (EIO);
293 293
294 294 if (suword32(diop, ufsvfsp->vfs_dio))
295 295 return (EFAULT);
296 296 return (0);
297 297 }
298 298
299 299 /*
300 300 * ufs_fiosdio
301 301 * Set delayed-io state. This ioctl is tailored
302 302 * to metamucil's needs and may change at any time.
303 303 */
304 304 int
305 305 ufs_fiosdio(
306 306 struct vnode *vp, /* file's vnode */
307 307 uint_t *diop, /* dio flag */
308 308 int flag, /* flag from ufs_ioctl */
309 309 struct cred *cr) /* credentials from ufs_ioctl */
310 310 {
311 311 uint_t dio; /* copy of user's dio */
312 312 struct inode *ip; /* inode for vp */
313 313 struct ufsvfs *ufsvfsp;
314 314 struct fs *fs;
315 315 struct ulockfs *ulp;
316 316 int error = 0;
317 317
318 318 #ifdef lint
319 319 flag = flag;
320 320 #endif
321 321
322 322 /* check input conditions */
323 323 if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
324 324 return (EPERM);
325 325
326 326 if (copyin(diop, &dio, sizeof (dio)))
327 327 return (EFAULT);
328 328
329 329 if (dio > 1)
330 330 return (EINVAL);
331 331
332 332 /* file system has been forcibly unmounted */
333 333 if (VTOI(vp)->i_ufsvfs == NULL)
334 334 return (EIO);
335 335
336 336 ip = VTOI(vp);
↓ open down ↓ |
336 lines elided |
↑ open up ↑ |
337 337 ufsvfsp = ip->i_ufsvfs;
338 338 ulp = &ufsvfsp->vfs_ulockfs;
339 339
340 340 /* logging file system; dio ignored */
341 341 if (TRANS_ISTRANS(ufsvfsp))
342 342 return (error);
343 343
344 344 /* hold the mutex to prevent race with a lockfs request */
345 345 vfs_lock_wait(vp->v_vfsp);
346 346 mutex_enter(&ulp->ul_lock);
347 - atomic_add_long(&ufs_quiesce_pend, 1);
347 + atomic_inc_ulong(&ufs_quiesce_pend);
348 348
349 349 if (ULOCKFS_IS_HLOCK(ulp)) {
350 350 error = EIO;
351 351 goto out;
352 352 }
353 353
354 354 if (ULOCKFS_IS_ELOCK(ulp)) {
355 355 error = EBUSY;
356 356 goto out;
357 357 }
358 358 /* wait for outstanding accesses to finish */
359 359 if (error = ufs_quiesce(ulp))
360 360 goto out;
361 361
362 362 /* flush w/invalidate */
363 363 if (error = ufs_flush(vp->v_vfsp))
364 364 goto out;
365 365
366 366 /*
367 367 * update dio
368 368 */
369 369 mutex_enter(&ufsvfsp->vfs_lock);
370 370 ufsvfsp->vfs_dio = dio;
371 371
372 372 /*
373 373 * enable/disable clean flag processing
374 374 */
375 375 fs = ip->i_fs;
376 376 if (fs->fs_ronly == 0 &&
377 377 fs->fs_clean != FSBAD &&
378 378 fs->fs_clean != FSLOG) {
379 379 if (dio)
380 380 fs->fs_clean = FSSUSPEND;
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
381 381 else
382 382 fs->fs_clean = FSACTIVE;
383 383 ufs_sbwrite(ufsvfsp);
384 384 mutex_exit(&ufsvfsp->vfs_lock);
385 385 } else
386 386 mutex_exit(&ufsvfsp->vfs_lock);
387 387 out:
388 388 /*
389 389 * we need this broadcast because of the ufs_quiesce call above
390 390 */
391 - atomic_add_long(&ufs_quiesce_pend, -1);
391 + atomic_dec_ulong(&ufs_quiesce_pend);
392 392 cv_broadcast(&ulp->ul_cv);
393 393 mutex_exit(&ulp->ul_lock);
394 394 vfs_unlock(vp->v_vfsp);
395 395 return (error);
396 396 }
397 397
398 398 /*
399 399 * ufs_fioffs - ioctl handler for flushing file system
400 400 */
401 401 /* ARGSUSED */
402 402 int
403 403 ufs_fioffs(
404 404 struct vnode *vp,
405 405 char *vap, /* must be NULL - reserved */
406 406 struct cred *cr) /* credentials from ufs_ioctl */
407 407 {
408 408 int error;
409 409 struct ufsvfs *ufsvfsp;
410 410 struct ulockfs *ulp;
411 411
412 412 /* file system has been forcibly unmounted */
413 413 ufsvfsp = VTOI(vp)->i_ufsvfs;
414 414 if (ufsvfsp == NULL)
415 415 return (EIO);
416 416
417 417 ulp = &ufsvfsp->vfs_ulockfs;
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
418 418
419 419 /*
420 420 * suspend the delete thread
421 421 * this must be done outside the lockfs locking protocol
422 422 */
423 423 vfs_lock_wait(vp->v_vfsp);
424 424 ufs_thread_suspend(&ufsvfsp->vfs_delete);
425 425
426 426 /* hold the mutex to prevent race with a lockfs request */
427 427 mutex_enter(&ulp->ul_lock);
428 - atomic_add_long(&ufs_quiesce_pend, 1);
428 + atomic_inc_ulong(&ufs_quiesce_pend);
429 429
430 430 if (ULOCKFS_IS_HLOCK(ulp)) {
431 431 error = EIO;
432 432 goto out;
433 433 }
434 434 if (ULOCKFS_IS_ELOCK(ulp)) {
435 435 error = EBUSY;
436 436 goto out;
437 437 }
438 438 /* wait for outstanding accesses to finish */
439 439 if (error = ufs_quiesce(ulp))
440 440 goto out;
441 441
442 442 /*
443 443 * If logging, and the logmap was marked as not rollable,
444 444 * make it rollable now, and start the trans_roll thread and
445 445 * the reclaim thread. The log at this point is safe to write to.
446 446 */
447 447 if (ufsvfsp->vfs_log) {
448 448 ml_unit_t *ul = ufsvfsp->vfs_log;
449 449 struct fs *fsp = ufsvfsp->vfs_fs;
450 450 int err;
451 451
452 452 if (ul->un_flags & LDL_NOROLL) {
453 453 ul->un_flags &= ~LDL_NOROLL;
454 454 logmap_start_roll(ul);
455 455 if (!fsp->fs_ronly && (fsp->fs_reclaim &
456 456 (FS_RECLAIM|FS_RECLAIMING))) {
457 457 fsp->fs_reclaim &= ~FS_RECLAIM;
458 458 fsp->fs_reclaim |= FS_RECLAIMING;
459 459 ufs_thread_start(&ufsvfsp->vfs_reclaim,
460 460 ufs_thread_reclaim, vp->v_vfsp);
461 461 if (!fsp->fs_ronly) {
462 462 TRANS_SBWRITE(ufsvfsp,
463 463 TOP_SBUPDATE_UPDATE);
464 464 if (err =
465 465 geterror(ufsvfsp->vfs_bufp)) {
466 466 refstr_t *mntpt;
467 467 mntpt = vfs_getmntpoint(
468 468 vp->v_vfsp);
469 469 cmn_err(CE_NOTE,
470 470 "Filesystem Flush "
471 471 "Failed to update "
472 472 "Reclaim Status for "
473 473 " %s, Write failed to "
474 474 "update superblock, "
475 475 "error %d",
476 476 refstr_value(mntpt),
477 477 err);
478 478 refstr_rele(mntpt);
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
479 479 }
480 480 }
481 481 }
482 482 }
483 483 }
484 484
485 485 /* synchronously flush dirty data and metadata */
486 486 error = ufs_flush(vp->v_vfsp);
487 487
488 488 out:
489 - atomic_add_long(&ufs_quiesce_pend, -1);
489 + atomic_dec_ulong(&ufs_quiesce_pend);
490 490 cv_broadcast(&ulp->ul_cv);
491 491 mutex_exit(&ulp->ul_lock);
492 492 vfs_unlock(vp->v_vfsp);
493 493
494 494 /*
495 495 * allow the delete thread to continue
496 496 */
497 497 ufs_thread_continue(&ufsvfsp->vfs_delete);
498 498 return (error);
499 499 }
500 500
501 501 /*
502 502 * ufs_fioisbusy
503 503 * Get number of references on this vnode.
504 504 * Contract-private interface for Legato's NetWorker product.
505 505 */
506 506 /* ARGSUSED */
507 507 int
508 508 ufs_fioisbusy(struct vnode *vp, int *isbusy, struct cred *cr)
509 509 {
510 510 int is_it_busy;
511 511
512 512 /*
513 513 * The caller holds one reference, there may be one in the dnlc
514 514 * so we need to flush it.
515 515 */
516 516 if (vp->v_count > 1)
517 517 dnlc_purge_vp(vp);
518 518 /*
519 519 * Since we've just flushed the dnlc and we hold a reference
520 520 * to this vnode, then anything but 1 means busy (this had
521 521 * BETTER not be zero!). Also, it's possible for someone to
522 522 * have this file mmap'ed with no additional reference count.
523 523 */
524 524 ASSERT(vp->v_count > 0);
525 525 if ((vp->v_count == 1) && (VTOI(vp)->i_mapcnt == 0))
526 526 is_it_busy = 0;
527 527 else
528 528 is_it_busy = 1;
529 529
530 530 if (suword32(isbusy, is_it_busy))
531 531 return (EFAULT);
532 532 return (0);
533 533 }
534 534
535 535 /* ARGSUSED */
536 536 int
537 537 ufs_fiodirectio(struct vnode *vp, int cmd, struct cred *cr)
538 538 {
539 539 int error = 0;
540 540 struct inode *ip = VTOI(vp);
541 541
542 542 /*
543 543 * Acquire reader lock and set/reset direct mode
544 544 */
545 545 rw_enter(&ip->i_contents, RW_READER);
546 546 mutex_enter(&ip->i_tlock);
547 547 if (cmd == DIRECTIO_ON)
548 548 ip->i_flag |= IDIRECTIO; /* enable direct mode */
549 549 else if (cmd == DIRECTIO_OFF)
550 550 ip->i_flag &= ~IDIRECTIO; /* disable direct mode */
551 551 else
552 552 error = EINVAL;
553 553 mutex_exit(&ip->i_tlock);
554 554 rw_exit(&ip->i_contents);
555 555 return (error);
556 556 }
557 557
558 558 /*
559 559 * ufs_fiotune
560 560 * Allow some tunables to be set on a mounted fs
561 561 */
562 562 int
563 563 ufs_fiotune(struct vnode *vp, struct fiotune *uftp, struct cred *cr)
564 564 {
565 565 struct fiotune ftp;
566 566 struct fs *fs;
567 567 struct ufsvfs *ufsvfsp;
568 568
569 569 /*
570 570 * must have sufficient privileges
571 571 */
572 572 if (secpolicy_fs_config(cr, vp->v_vfsp) != 0)
573 573 return (EPERM);
574 574
575 575 /*
576 576 * get user's copy
577 577 */
578 578 if (copyin(uftp, &ftp, sizeof (ftp)))
579 579 return (EFAULT);
580 580
581 581 /*
582 582 * some minimal sanity checks
583 583 */
584 584 if ((ftp.maxcontig <= 0) ||
585 585 (ftp.rotdelay != 0) ||
586 586 (ftp.maxbpg <= 0) ||
587 587 (ftp.minfree < 0) ||
588 588 (ftp.minfree > 99) ||
589 589 ((ftp.optim != FS_OPTTIME) && (ftp.optim != FS_OPTSPACE)))
590 590 return (EINVAL);
591 591
592 592 /*
593 593 * update superblock but don't write it! If it gets out, fine.
594 594 */
595 595 fs = VTOI(vp)->i_fs;
596 596
597 597 fs->fs_maxcontig = ftp.maxcontig;
598 598 fs->fs_rotdelay = ftp.rotdelay;
599 599 fs->fs_maxbpg = ftp.maxbpg;
600 600 fs->fs_minfree = ftp.minfree;
601 601 fs->fs_optim = ftp.optim;
602 602
603 603 /*
604 604 * Adjust cluster based on the new maxcontig. The cluster size
605 605 * can be any positive value. The check for this is done above.
606 606 */
607 607 ufsvfsp = VTOI(vp)->i_ufsvfs;
608 608 ufsvfsp->vfs_ioclustsz = fs->fs_bsize * fs->fs_maxcontig;
609 609
610 610 /*
611 611 * Adjust minfrags from minfree
612 612 */
613 613 ufsvfsp->vfs_minfrags = (int)((int64_t)fs->fs_dsize *
614 614 fs->fs_minfree / 100);
615 615
616 616 /*
617 617 * Write the superblock
618 618 */
619 619 if (fs->fs_ronly == 0) {
620 620 TRANS_BEGIN_ASYNC(ufsvfsp, TOP_SBUPDATE_UPDATE,
621 621 TOP_SBWRITE_SIZE);
622 622 TRANS_SBWRITE(ufsvfsp, TOP_SBUPDATE_UPDATE);
623 623 TRANS_END_ASYNC(ufsvfsp, TOP_SBUPDATE_UPDATE, TOP_SBWRITE_SIZE);
624 624 }
625 625
626 626 return (0);
627 627 }
628 628
629 629 /*
630 630 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
631 631 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
632 632 */
633 633 int
634 634 ufs_fio_holey(vnode_t *vp, int cmd, offset_t *off)
635 635 {
636 636 inode_t *ip = VTOI(vp);
637 637 u_offset_t noff = (u_offset_t)*off; /* new offset */
638 638 u_offset_t isz;
639 639 int error;
640 640 boolean_t hole;
641 641
642 642 rw_enter(&ip->i_contents, RW_READER);
643 643 isz = ip->i_size;
644 644 if (noff >= isz) {
645 645 rw_exit(&ip->i_contents);
646 646 return (ENXIO);
647 647 }
648 648
649 649 /*
650 650 * Check for the usual case where a file has no holes.
651 651 * If so we can optimise to set the end of the file as the first
652 652 * (virtual) hole. This avoids bmap_find() searching through
653 653 * every block in the file for a (non-existent) hole.
654 654 */
655 655 if (!bmap_has_holes(ip)) {
656 656 rw_exit(&ip->i_contents);
657 657 if (cmd == _FIO_SEEK_HOLE) {
658 658 *off = isz;
659 659 return (0);
660 660 }
661 661 /* *off must already point to valid data (non hole) */
662 662 return (0);
663 663 }
664 664
665 665 /*
666 666 * Calling bmap_read() one block at a time on a 1TB file takes forever,
667 667 * so we use a special function to search for holes or blocks.
668 668 */
669 669 if (cmd == _FIO_SEEK_HOLE)
670 670 hole = B_TRUE;
671 671 else
672 672 hole = B_FALSE;
673 673 error = bmap_find(ip, hole, &noff);
674 674 rw_exit(&ip->i_contents);
675 675
676 676 /* end of file? */
677 677 if (error == ENXIO) {
678 678 /*
679 679 * Handle the virtual hole at the end of file.
680 680 */
681 681 if (cmd == _FIO_SEEK_HOLE) {
682 682 *off = isz;
683 683 return (0);
684 684 }
685 685 return (ENXIO);
686 686 }
687 687 if (noff < *off)
688 688 return (error);
689 689 *off = noff;
690 690 return (error);
691 691 }
692 692
693 693 int
694 694 ufs_mark_compressed(struct vnode *vp)
695 695 {
696 696 struct inode *ip = VTOI(vp);
697 697 struct ufsvfs *ufsvfsp = ip->i_ufsvfs;
698 698
699 699 if (vp->v_type != VREG)
700 700 return (EINVAL);
701 701
702 702 rw_enter(&ip->i_contents, RW_WRITER);
703 703 ip->i_cflags |= ICOMPRESS;
704 704 TRANS_INODE(ufsvfsp, ip);
705 705 ip->i_flag |= (ICHG|ISEQ);
706 706 ip->i_seq++;
707 707 if (!TRANS_ISTRANS(ufsvfsp))
708 708 ufs_iupdat(ip, I_ASYNC);
709 709 rw_exit(&ip->i_contents);
710 710
711 711 return (0);
712 712 }
↓ open down ↓ |
213 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX