3527 | | for (unsigned int pass = 1; pass <= 2; pass++) |
| 3528 | // pass 1: try to fit onto an existing file system with enought free space |
| 3529 | // pass 2: fit onto the file system with the lowest priority files to be expired |
| 3530 | // this is used only with multiple file systems |
| 3531 | // Estimates are made by simulating each expiry until one of |
| 3532 | // the file systems has enough sapce to fit the new file. |
| 3533 | // pass 3: fit onto the first file system that will take it with lowest |
| 3534 | // priority files on this file system expired |
| 3535 | for (unsigned int pass = 1; pass <= 3; pass++) |
3533 | | long long desiredSpaceKB = 0; |
3534 | | FileSystemInfo *fs = *fslistit; |
3535 | | if (expirer) |
3536 | | desiredSpaceKB = expirer->GetDesiredSpace(fs->fsID); |
| 3541 | // setup a container of remaing space for all the file systems |
| 3542 | QMap <int , long long> remainingSpaceKB; |
| 3543 | for (fslistit = fsInfoList.begin(); |
| 3544 | fslistit != fsInfoList.end(); fslistit++) |
| 3545 | { |
| 3546 | remainingSpaceKB[(*fslistit)->fsID] = (*fslistit)->freeSpaceKB; |
| 3547 | } |
3546 | | if (pass == 1) |
3547 | | VERBOSE(VB_FILE, QString("'%1' will record in '%2' which " |
3548 | | "has %3 MiB free. This recording could use a max " |
3549 | | "of %4 MiB and the AutoExpirer wants to keep %5 " |
3550 | | "MiB free.") |
3551 | | .arg(pginfo->title).arg(pginfo->pathname) |
3552 | | .arg(fs->freeSpaceKB / 1024).arg(maxSizeKB / 1024) |
3553 | | .arg(desiredSpaceKB / 1024)); |
3554 | | else |
3555 | | VERBOSE(VB_FILE, QString("'%1' will record in '%2' " |
| 3557 | // find the filesystem its on |
| 3558 | FileSystemInfo *fs=NULL; |
| 3559 | for (fslistit = fsInfoList.begin(); |
| 3560 | fslistit != fsInfoList.end(); fslistit++) |
| 3561 | { |
| 3562 | QString filename = (*fslistit)->directory + "/" + (*it)->pathname; |
| 3563 | QFile checkFile(filename); |
| 3564 | |
| 3565 | if (checkFile.exists()) |
| 3566 | { |
| 3567 | fs = *fslistit; |
| 3568 | break; |
| 3569 | } |
| 3570 | |
| 3571 | } |
| 3572 | |
| 3573 | if (fs == NULL) |
| 3574 | { |
| 3575 | VERBOSE(VB_IMPORTANT, QString("Unable to match '%1'" |
| 3576 | " to any file system. " |
| 3577 | "Falling back to old file placement.") |
| 3578 | .arg((*it)->pathname)); |
| 3579 | break; |
| 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | // add this files size to the remaing free space |
| 3584 | remainingSpaceKB[fs->fsID] += (*it)->filesize / 1024; |
| 3585 | |
| 3586 | // check if we have enough space for new file |
| 3587 | long long desiredSpaceKB = expirer->GetDesiredSpace(fs->fsID); |
| 3588 | |
| 3589 | if (remainingSpaceKB[fs->fsID] > (desiredSpaceKB + maxSizeKB)) |
| 3590 | { |
| 3591 | pginfo->pathname = fs->directory; |
| 3592 | fsID = fs->fsID; |
| 3593 | |
| 3594 | VERBOSE(VB_IMPORTANT, QString("'%1' will record in '%2' " |
| 3618 | if ((fs->hostname == pginfo->hostname) && |
| 3619 | (dirlist.contains(fs->directory)) && |
| 3620 | ((pass == 3) || |
| 3621 | (fs->freeSpaceKB > (desiredSpaceKB + maxSizeKB)))) |
| 3622 | { |
| 3623 | pginfo->pathname = fs->directory; |
| 3624 | fsID = fs->fsID; |
| 3625 | |
| 3626 | if (pass == 1) |
| 3627 | VERBOSE(VB_FILE, QString("'%1' will record in '%2' which " |
| 3628 | "has %3 MiB free. This recording could use a max " |
| 3629 | "of %4 MiB and the AutoExpirer wants to keep %5 " |
| 3630 | "MiB free.") |
| 3631 | .arg(pginfo->title).arg(pginfo->pathname) |
| 3632 | .arg(fs->freeSpaceKB / 1024).arg(maxSizeKB / 1024) |
| 3633 | .arg(desiredSpaceKB / 1024)); |
| 3634 | else |
| 3635 | VERBOSE(VB_FILE, QString("'%1' will record in '%2' " |
| 3636 | "although there is only %3 MiB free and the " |
| 3637 | "AutoExpirer wants at least %4 MiB. Something " |
| 3638 | "will have to be deleted or expired in order for " |
| 3639 | "this recording to complete successfully.") |
| 3640 | .arg(pginfo->title).arg(pginfo->pathname) |
| 3641 | .arg(fs->freeSpaceKB / 1024) |
| 3642 | .arg(desiredSpaceKB / 1024)); |
| 3643 | |
| 3644 | foundDir = true; |
| 3645 | break; |
| 3646 | } |
| 3647 | } |
| 3648 | } |
| 3649 | |