Merge "storagemenager: Skip fstrim while doing block based checkpoint" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-17 16:46:38 +00:00
committed by Android (Google) Code Review

View File

@@ -1074,6 +1074,15 @@ class StorageManagerService extends IStorageManager.Stub
mVold.onUserStarted(userId, packages, appIds, sandboxIds); mVold.onUserStarted(userId, packages, appIds, sandboxIds);
} }
private boolean supportsBlockCheckpoint() throws RemoteException {
// Only the system process is permitted to start checkpoints
if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
throw new SecurityException("no permission to check block based checkpoint support");
}
return mVold.supportsBlockCheckpoint();
}
@Override @Override
public void onAwakeStateChanged(boolean isAwake) { public void onAwakeStateChanged(boolean isAwake) {
// Ignored // Ignored
@@ -2116,37 +2125,45 @@ class StorageManagerService extends IStorageManager.Stub
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS); enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
try { try {
mVold.fstrim(flags, new IVoldTaskListener.Stub() { // Block based checkpoint process runs fstrim. So, if checkpoint is in progress
@Override // (first boot after OTA), We skip idle maintenance and make sure the last
public void onStatus(int status, PersistableBundle extras) { // fstrim time is still updated. If file based checkpoints are used, we run
dispatchOnStatus(listener, status, extras); // idle maintenance (GC + fstrim) regardless of checkpoint status.
if (!needsCheckpoint() || !supportsBlockCheckpoint()) {
mVold.fstrim(flags, new IVoldTaskListener.Stub() {
@Override
public void onStatus(int status, PersistableBundle extras) {
dispatchOnStatus(listener, status, extras);
// Ignore trim failures // Ignore trim failures
if (status != 0) return; if (status != 0) return;
final String path = extras.getString("path"); final String path = extras.getString("path");
final long bytes = extras.getLong("bytes"); final long bytes = extras.getLong("bytes");
final long time = extras.getLong("time"); final long time = extras.getLong("time");
final DropBoxManager dropBox = mContext.getSystemService(DropBoxManager.class); final DropBoxManager dropBox = mContext.getSystemService(DropBoxManager.class);
dropBox.addText(TAG_STORAGE_TRIM, scrubPath(path) + " " + bytes + " " + time); dropBox.addText(TAG_STORAGE_TRIM, scrubPath(path) + " " + bytes + " " + time);
synchronized (mLock) { synchronized (mLock) {
final VolumeRecord rec = findRecordForPath(path); final VolumeRecord rec = findRecordForPath(path);
if (rec != null) { if (rec != null) {
rec.lastTrimMillis = System.currentTimeMillis(); rec.lastTrimMillis = System.currentTimeMillis();
writeSettingsLocked(); writeSettingsLocked();
}
} }
} }
}
@Override @Override
public void onFinished(int status, PersistableBundle extras) { public void onFinished(int status, PersistableBundle extras) {
dispatchOnFinished(listener, status, extras); dispatchOnFinished(listener, status, extras);
// TODO: benchmark when desired // TODO: benchmark when desired
} }
}); });
} else {
Slog.i(TAG, "Skipping fstrim - block based checkpoint in progress");
}
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowAsRuntimeException(); throw e.rethrowAsRuntimeException();
} }
@@ -2156,18 +2173,26 @@ class StorageManagerService extends IStorageManager.Stub
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS); enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
try { try {
mVold.runIdleMaint(new IVoldTaskListener.Stub() { // Block based checkpoint process runs fstrim. So, if checkpoint is in progress
@Override // (first boot after OTA), We skip idle maintenance and make sure the last
public void onStatus(int status, PersistableBundle extras) { // fstrim time is still updated. If file based checkpoints are used, we run
// Not currently used // idle maintenance (GC + fstrim) regardless of checkpoint status.
} if (!needsCheckpoint() || !supportsBlockCheckpoint()) {
@Override mVold.runIdleMaint(new IVoldTaskListener.Stub() {
public void onFinished(int status, PersistableBundle extras) { @Override
if (callback != null) { public void onStatus(int status, PersistableBundle extras) {
BackgroundThread.getHandler().post(callback); // Not currently used
} }
} @Override
}); public void onFinished(int status, PersistableBundle extras) {
if (callback != null) {
BackgroundThread.getHandler().post(callback);
}
}
});
} else {
Slog.i(TAG, "Skipping idle maintenance - block based checkpoint in progress");
}
} catch (Exception e) { } catch (Exception e) {
Slog.wtf(TAG, e); Slog.wtf(TAG, e);
} }